题目:Leading and Trailing  LightOJ - 1282 

题意:n^k的前三位数, 后三位数。

参考博客:UVA-11029 Leading and Trailing

代码:

#include<string.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int q_pow(LL a, LL b){
   LL base = a, ans = 1;
   while(b){
       if(b & 1)ans = (ans * base) % 1000;
       base = (base * base) % 1000;
       b >>= 1;
   }
   return ans;
}
int main(){
    int T;
    cin>>T;
    int ca = 0;
    while(T--){
        LL n, k;
        scanf("%lld %lld", &n, &k);
        int ans1 = q_pow(n, k);
        double d = k * log10(n);
        int ans2 = pow(10, (d-(int)d))*100;
        printf("Case %d: %d %03d\n",++ca, ans2, ans1);

    }
}

 

posted on 2019-04-10 19:30  Refused  阅读(36)  评论(0)    收藏  举报