Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一直wa,跟过了的程序对了1000*1000的数据都一样。有大牛帮我看看吗?#include <cstring> #include <cstdio> const int MAX_SIZE = 10000; bool notprime[MAX_SIZE]; int prime1[MAX_SIZE],primenum; void init() { memset(notprime,0,sizeof(notprime)); primenum = 0; for(int i = 2;i < MAX_SIZE;++i) { if(!notprime[i]) { prime1[primenum++] = i; for(int j = i*i;j < MAX_SIZE;j += i) notprime[j] = 1; } } } long long power(long long k,long long n,int MOD){ long long ans,sp; for(ans=1,sp=k%MOD;n>0;n>>=1,sp=sp*sp%MOD) if(n&1)ans=ans*sp%MOD; return ans; } struct ReturnType { long long u,v,d; }; ReturnType Extended_Euclid(long long a,long long b) { ReturnType r; if(b) { r = Extended_Euclid(b,a%b); long long v = r.v; r.v = r.u-a/b*r.v; r.u = v; } else { r.u = 1; r.v = 0; r.d = a; } return r; } int DivMod(long long a,long long b,int p) { ReturnType r = Extended_Euclid(b,p); r.u %= p; if(r.u < 0) r.u += p; return ((a%p)*(r.u%p))%p; } int main() { long long a,b,temp = 1; init(); while(scanf("%lld%lld",&a,&b) == 2) { if(a % 9901 == 0) { temp = 0; } else if(b == 0) { temp = 1; } else{ temp = 1; for(int i = 0;prime1[i]*prime1[i] <= a;++i) { if(a % prime1[i] == 0) { int t = 0; while(a%prime1[i] == 0) { ++t; a /= prime1[i]; } temp *= DivMod(power(prime1[i],b*t+1,9901)-1,prime1[i]-1,9901); temp %= 9901; } } if(a != 1) temp *= DivMod(power(a,b+1,9901)-1,a-1,9901); temp %= 9901; } printf("%lld\n",temp); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator