#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int power(int a,int b,int c)
{
int res=1;
a%=c;
while(b)
{
if(b&1)
res=(res*a)%c;
a=(a*a)%c;
b>>=1;
}
return res;
}
int main()
{
int t,ca=1;
cin>>t;
while(t--)
{
int n,k,x,y;
scanf("%d%d",&n,&k);
//公式推导,得前三位求法
//设n^k=a.bc*10^m(除开前三位,其余的约掉了)
//lg(n^k) = lg(a.bc * 10^m)
//k * lg(n) = lg(a.bc) + lg(10^m) = lg(a.bc) + m
//m为k * lg(n)的整数部分,lg(a.bc)为k * lg(n)的小数部分
//x = lg(a.bc) = k * lg(n) - m = k * lg(n) - (int)(k * lg(n))
//a.bc = pow(10, x);
//abc = a.bc * 100;
double m=k*log10(n)-(int)(k*log10(n));
m=pow(10,m);
x=m*100;
//------------------------------------------------------------
y=power(n,k,1000);
printf("Case %d: %d %03d\n",ca++,x,y);
}
}
LightOJ - 1282
最新推荐文章于 2021-05-22 22:33:32 发布