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 |
这是我的代码,老是TLE,跪求大佬#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <cstdio> using namespace std; typedef long long int LL; bool judge(LL x) { LL i; if(x<2) return true; for(i=2;i<=sqrt(x);i++) { if(!(x%i)) return true; } return false; } int powe_m(LL a,LL b) { LL ans=1; LL tmp=a; LL mod=b; while(b!=0) { if((b&1)) { ans=((tmp%mod)*(ans%mod))%mod; } tmp=((tmp%mod)*(tmp%mod))%mod; b=b>>1; } return ans%mod; } int main() { LL a,p; int ap; int flag1,flag2; while(scanf("%d %d",&p,&a)!=EOF) { if(p==0&&a==0) break; flag1=flag2=0; flag1=judge(p); if(flag1!=true) { printf("no\n"); continue; } ap=powe_m(a,p); if(flag1) if(ap==a) { flag2=1; } if(flag1&&flag2) { printf("yes\n"); } else { printf("no\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator