先頭と末尾のLightOJ - 1282(クイックパワー)
質問の意味:
すなわち:非常に重要な迅速なパワー、最初の3の最終結果を求めて、最後の3
ソリューション:
ここに関連する問題が多数あるので、最初に考えたのは、確かにJavaのBigIntegerのですが、TLE ...
悲劇の
いくつかの闘争の後、またはリクエストに応じて電源操作の前に、出てくると、本当に問題の解決や、あまりにも多くの食べ物を見つける見えたくありませんでした3つの固定式があります。
int ans1=(int)pow(10.0,2+fmod(k*log10(n),1));
その後、3のために、唯一の高速パワーで、モジュロ演算を行うことができ、その結果はかなりされています
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<map>
#define lowbit(x) x&(-x)
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000
using namespace std;
const double pi=acos(-1.0);
const int maxn=1000010;
const double eps=1e-8;
int t;
int n,k;
int modPow(int a,int b){
int r=1;
a%=1000;
while(b){
if(b&1){
r=r*a%mod;
}
b>>=1;
a=a*a%mod;
}
return r;
}
int main(){
scanf("%d",&t);
int cnt=1;
while(t--){
scanf("%d%d",&n,&k);
int ans1=(int)pow(10.0,2+fmod(k*log10(n),1));
while(ans1>1000){
ans1/=10;
}
int ans2=modPow(n,k);
ans2%=1000; //最终结果可能大于1000,需要再次取模,踩过坑
printf("Case %d: %d %03d\n",cnt++,ans1,ans2);
}
return 0;
}