标签:偶数 mes should string contains res base int c代码
Input
Output
Sample Input
2 3
Sample Output
15
Hint
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include "cstdio" using namespace std; #define ll long long #define mod 9901 #define N 1000010 ll prime[N]; bool vis[N]; ll p[N]; ll pn=0; ll POW(ll a,ll n) { ll base=a,ret=1; while(n) { if(n&1) ret=(ret%mod*base)%mod; base=(base*base)%mod; n>>=1; } return ret%mod; } __int64 sum(__int64 p,__int64 n) //递归二分求 (1 + p + p^2 + p^3 +...+ p^n)%mod { //奇数二分式 (1 + p + p^2 +...+ p^(n/2)) * (1 + p^(n/2+1)) if(n==0) //偶数二分式 (1 + p + p^2 +...+ p^(n/2-1)) * (1+p^(n/2+1)) + p^(n/2) return 1; if(n%2) //n为奇数, return (sum(p,n/2)*(1+POW(p,n/2+1)))%mod; else //n为偶数 return (sum(p,n/2-1)*(1+POW(p,n/2+1))+POW(p,n/2))%mod; } int main() { for (int i = 2; i < N; i++) { if (vis[i]) continue; prime[pn++] = i; for (int j = i; j < N; j += i) vis[j] = 1; } ll a,b; while(~scanf("%lld%lld",&a,&b)) { memset(p,0,sizeof(p)); ll ans=1; for(int i=0;prime[i]*prime[i]<=a;i++) { ll tem=0; while(a%prime[i]==0) { tem++; a/=prime[i]; } if(tem) { p[prime[i]]=tem; } } if(a!=1) { ll rev=POW(a-1,9899); ll res=sum(a,b); ans=ans*res%mod; } for(int i=0;i<pn;i++) { if(p[prime[i]]) { ll rev=POW(prime[i]-1,9899); ll res=sum(prime[i],p[prime[i]]*b); ans=ans*res%mod; } } cout<<ans<<endl; } }
标签:偶数 mes should string contains res base int c代码
原文地址:http://www.cnblogs.com/ygtzds/p/7860689.html