来源:POJ1845
就是一个计数,中间使用了二分,很机智的做法
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;//竟然是有求p^1+p^2+...+p^n的模板,JZ
typedef long long LL;
const int MAXN = 10010;
const int MOD = 9901;
LL quick_pow(LL a,LL n){
LL res=1;
LL temp=a%MOD;
while(n){
if(n&1) res=(res*temp)%MOD;
temp=temp*temp%MOD;
n>>=1;
}
return res;
}
LL sum(LL p,LL n){
if(p==0) return 0;
if(n==0) return 1;
if(n&1){
return ((1+quick_pow(p,n/2+1))%MOD*sum(p,n/2)%MOD)%MOD;
}
else{
return ((1+quick_pow(p,n/2+1))%MOD*sum(p,n/2-1)+quick_pow(p,n/2)%MOD)%MOD;
}
}
LL p[MAXN],n[MAXN];
int main(){
LL a,b;
while(scanf("%lld%lld",&a,&b)!=EOF){
int k=0;
for(int i=2;i<=a/i;){
if(a%i==0){
p[k]=i;
n[k]=0;
while(!(a%i)){
n[k]++;
a/=i;
}
k++;
}
if(i==2){
i++;
}
else
i+=2;
}
if(a!=1){
p[k]=a;
n[k++]=1;
}
LL ans=1;
for(int i=0;i<k;i++)
{
ans=(ans*(sum(p[i],n[i]*b)%MOD))%MOD;
}
cout<<ans<<endl;
}
return 0;
}
756

被折叠的 条评论
为什么被折叠?



