这道题的后三位直接快速幂即可,但是输出需要处理一下,不够的补0即可。前三位我们可以利用log10 n运算,我们就可以得到一个数,那么很明显这个数整数部分是科学计数法中10的倍数,小数部分就是对应的数值了,对应乘100正好可以得到三位数。
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define LL long longconst LL mod = 1000LL;LL quick_pow(LL a, LL b){ //快速幂 LL ret = 1; a %= mod; while(b){ if(b&1) ret = (ret*a)%mod; b >>= 1; a = (a*a)%mod; } return ret;}//fmod(x, 1); 表示取x的小数位int main(){ int T; scanf("%d", &T); for(int kase = 1; kase <= T; kase++){ LL n, k; scanf("%lld %lld", &n, &k); PRintf("Case %d: %lld %03lld/n", kase, (LL)pow(10.0,2.0+fmod(k*log10(1.0*n),1) ), quick_pow(n, k));// } return 0;}新闻热点
疑难解答