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

新手————

Posted by 13926491 at 2016-03-04 20:15:54 on Problem 3641
#include<stdio.h>
#include<math.h>
long long q;
bool isis(int num)
{
	int i;
	int upper=sqrt(num);
	for(i=2;i<=upper;i++)
	{
		if(num%i==0)
		{
			return false;
		}

	}return true;
}

long long  pow4(long long aa,long long b)
{
	long long r=1,base=aa;
	while(b!=0)
    {
        if(b&1)
            {
            r%=q;
            r*=base;
            }
        base=base*base%q;
        b>>=1;
    }
    return r;
}

int main()
{
	long long aa;
	while(scanf("%lld%lld",&q,&aa)!=EOF)
	{
		if(q==0&&aa==0)break;
		if(isis(q)){printf("no\n");continue;}
		long long w=pow4(aa,q);
		if(w%q==aa)printf("yes\n");
		else printf("no\n");
	}
}

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