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

这是我的代码,老是TLE,跪求大佬

Posted by mimori_Tay at 2018-11-14 19:12:51 on Problem 3641
#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:
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