题意:http://www.lightoj.com/volume_showproblem.php?problem=1282
n^k = a.bc * 10.0^m;等式两边同时加上log10
k*log10(n) = log10(a.bc) + m;
m为k * log10(n)的整数部分,log10(a.bc)为k * lg(n)的小数部分;
x = log10(a.bc) = k*log10(n) - m = k*log10(n) - (int)k*log10(n);
x = pow(10.0, x);
double x=k*log10(n)-(LL)(k*log10(n));
int y=(int)(pow(10,x)*100);
注意后三位 不够前补0 %03d
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<vector> #include<math.h> #include<string> using namespace std; #define INF 0x3f3f3f3f #define LL long long #define N 10000009 #define Lson rood<<1 #define Rson rood<<1|1 int poww(int a,int b) { int c=1; while(b) { if(b&1) c=c*a%1000; b=b/2; a=a*a%1000; } return c; } int main() { int T,t=1; scanf("%d",&T); while(T--) { int n,k; scanf("%d %d",&n,&k); double x=k*log10(n)-(int)(k*log10(n)); int y=(int)(pow(10,x)*100); printf("Case %d: %d %03d ",t++,y,poww(n%1000,k)); } return 0; }