Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

正如楼下所说,把int换成longlong就过了,附ac代码

Posted by 920394589 at 2017-08-18 14:17:00 on Problem 3641
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator