用log10来求前N位
f(n)=n^k tmp=log10f(n)=klog10n tmp=tmp-floor(tmp) tmp=10^tmp //再放大相应的位数就可以了~ |
#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<iomanip>
#include<map>
#include<vector>
#include<queue>
#include<stack>
//#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int N = 1050;
long long PowerMod(long long a, long long b,int c)
{
long long ans=1;
a%=c;
while(b>0)
{
if(b&1)
ans=ans*a%c;
b>>=1;
a=a*a%c;
}
return ans;
}
int lg(long long a,long long b)
{
double tmp=b*log10(a*1.0);
tmp-=floor(tmp); //整数部分决定位数
tmp=pow(10,tmp);
while(tmp<100) //需要前几位
{
tmp*=10;
}
return (int)tmp;
}
int main()
{
int t;
cin>>t;
int casee=1;
LL n,k;
while(t--)
{
cin>>n>>k;
printf("Case %d: %.3d %.3lldn",casee++,lg(n,k),PowerMod(n,k,1000));
}
return 0;
}
- 版权声明:本文基于《知识共享署名-相同方式共享 3.0 中国大陆许可协议》发布,转载请遵循本协议
- 文章链接:http://www.carlstedt.cn/archives/74 (转载时请注明本文出处及文章链接)


发表评论
快来吐槽一下吧!