http://poj.org/problem?id=3641
练手用,结果念题不清,以为是奇偶数WA了一发
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
bool judge_prime(ll k)
{
ll i;
ll u=int(sqrt(k*1.0));
for(i=;i<=u;i++)
{
if(k%i==)
return ;
}
return ;
}
ll mod_pow(ll x,ll n,ll mod)
{
ll res=;
while(n>)
{
if(n&) res=res*x%mod;
x=x*x%mod;
n>>=;
}
return res;
}
int main()
{
ll num=,a,p;
while(~scanf("%lld %lld",&p,&a))
{
if(p==&&a==) {num=;}
else{
if(judge_prime(p)) cout<<"no"<<endl;
else{
num=mod_pow(a,p,p);
if(num==a) cout<<"yes"<<endl;
else cout<<"no"<<endl;}}
}
return ;
}