Leading and Trailing LightOJ - 1282

Leading and Trailing LightOJ - 1282 (n^k 的前三个数) You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.Input Input starts with an integer T (≤ 1000), denoting the number 阅读详情

求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;
 }
LightOJ 1282 Leading and Trailing LightOJ 1282 Leading and Trailing 题目链接 You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nkn^knk. Input Input starts wi... 阅读详情

相关推荐

LightOJ - 1282 Leading and Trailing

LightOJ - 1282 Leading and Trailing 传送门:LightOJ - 1282 题意 给你两个数n,kn,kn,k,让你求nknkn^k的前三位和后三位各是多少。 1≤n&amp;lt;231,1≤k≤1071≤n&amp;lt;231,1≤k≤1071 \le n \lt 2^{31},1 \le k \le 10^7 题解 后三位很好想,直接快速幂搞一下,膜100...

fnoi11awyfeng的博客 344

lightoj 1282 Leading and Trailing

题目大意就是给你 n 和 k 让你求出n的k次方的前三位数和后三位数 直接求肯定不可能,求后三位可以直接快速幂求取 但是前三位就恶心了,其实是需要一个知识点——就是要把大数转化成整数和小数的形式。  任何数n可以化成10^a,而本题是求n^k,所以n=10^(a*k)=10^(i+d)=10^i*10^d,其中i是a*k的整数部分,d是a*k的小数部分。  d可以由fmod(a*k,1)求

W_904038290的博客 436

LightOJ1282 Leading and Trailing

1 /* 2 LightOJ1282 Leading and Trailing 3 http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1282 4 数论 fmod 5 fmod题。 6 求n^k的前三位 7 n可以写成10^a(a为小数)的形式。 8 因此原式=1...

weixin_30342209的博客 76

LightOJ 1282 Leading and Trailing

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/E Leading and Trailing Description You are given two integers: n and k, your task is to find the most signi

大太阳 1351

lightoj 1282 - Leading and Trailing 【数学】

1282 - Leading and Trailing     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are given two integers: n and k, your task is to

世界很大 690

Lightoj 1282 Leading and Trailing

Leading and TrailingYou are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.Input Input starts with an integer T (≤ 1000),

楚江枫 512

Leading and Trailing LightOJ - 1282 题解

LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位。 \(2<=n<2^{31}\),\(1<=k<10^{7}\) 并且\(n^{k}\)至少有6位数 解题思路 这个题目需要解决两个问题 输出\(n^{k}\)的前三位 输出\(n^{k}\)的...

weixin_30347009的博客 132

Lightoj 1282 (Leading and Trailing)

Leading and Trailing Description You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input st

渣渣眼里没有水题 401

快速幂 E - Leading and Trailing LightOJ - 1282

E - Leading and Trailing LightOJ - 1282 快速幂主要是把n拆成2进制位,如果这一位有那么就乘,没有就不乘,而计数器也就是x是不断推进的,从x->x^2->x^4直到n的最高位精髓在于取模,后一步的要求结果只与前一步的模后数据有关 。 对于后三个数用了log10.log函数对求n^k这种问题还是很有用的。没想出来。 1 #...

dieche3140的博客 175

lightoj 1282 Leading and Trailing

You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1000), denoting the num

Kelisiya 437

lightoj1282 - Leading and Trailing

1282 - Leading and Trailing     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are given two integers: n and k, your task is to

走一步再走一步 530

Leading and TrailingLightOJ-1282

Problem Description You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1...

Alex_McAvoy的博客 344

Leading and Trailing LightOJ 1282

题目链接: 点我You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. InputInput starts with an integer T (≤ 1000), denoting the

wood 394

LightOJ - 1282 Leading and Trailing 对数转换

题目+类型 一、 题目 Description You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of n^k. Input Input starts with an integer

Summer_via的博客 686

LightOJ - 1282 Leading and Trailing

n^k的前三位

a free man 515
上一篇: Max Sum HDU - 1003
下一篇: Large Division LightOJ - 1214
klchen0112
博客等级 码龄9年 3粉丝 120原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值