Leading and Trailing LightOJ - 1282

求n^k的前三位和后三位

  1. 后三位快速幂即可得到
  2. 对于前三位
    1. a.bc * 10^t = n^k
    2. log_{10}{a.bc} + t = klog_{10|{n}
    3. 所以log_{10}{a.bc} 是klog_{10|{n}的小数部分
    4. a.bc = 1000 * klog_{10|{n} 的整数部分
 #include<bits/stdc++.h>
 using namespace std;
 #define fst first
 #define sec second
 #define sci(num) scanf("%d",&num)
 #define scl(num) scanf("%lld",&num)
 #define mem(a,b) memset(a,b,sizeof a)
 #define cpy(a,b) memcopy(a,b,sizeof b)
 typedef long long LL;
 typedef pair<int,int> P;
 const int MAX_N = 510;
 const int MAX_M = 10000;
 int mpow(int a,int n,int mod) {
     int ans = 1;
     while (n) {
         if (n & 1) ans = ans * a % mod;
         a = a * a % mod;
         n >>= 1;
     }
     return ans;
 }
 int main() {
     int T;
     cin >> T;
     for (int cs =1; cs <= T;cs++) {
         LL N,K;
         cin >> N >> K;
         double x =  K* log10(N) -(LL) (K* log10(N));
         //cout <<  pow(10,x) << endl;
         LL ans1 = 100 * pow(10,x);
         LL ans2 =mpow(N % 1000,K,1000);
         cout << "Case " << cs << ": ";
         printf("%lld %03lld\n",ans1,ans2);
     }
     return 0;
 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值