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 |
正如楼下所说,把int换成longlong就过了,附ac代码#include<stdio.h> typedef long long LL; int P(LL t){ for(int i=2;i*i<=t;++i){ if(t%i==0)return 0; } return 1; } LL pow(LL p,LL a){ LL pp = p; LL ret = 1; a%=pp; while(p){ if(p&1)ret=ret*a%pp; a=a*a%pp; p>>=1; } return ret; } int main(){ LL p,a; while(scanf("%lld%lld",&p,&a)==2){ if(p==0||a==0)break; if(P(p)){ printf("no\n"); continue; } LL ret = pow(p,a); printf("%s\n",ret==a?"yes":"no"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator