#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define LL long long
#define REP(i,MAX) for(int i = 0; i<MAX; i++)
#define MAX 10001
using namespace std;
bool isPrime(LL n)
{
if(n == 1) return false;
if(n == 2) return true;
LL sqr = sqrt(n);
for (LL i = 2; i <= sqr; i++)
{
if(n%i == 0){
return false;
}
}
return true;
}
LL big_mod(LL base, LL power, LL mod)
{
if(power==0) return 1;
else if(power%2==1)
{
LL p1 = base % mod;
LL p2 = (big_mod(base,power-1,mod))%mod;
return (p1*p2)%mod;
}
else if(power%2==0)
{
LL p1 = (big_mod(base,power/2,mod))%mod;
return (p1*p1)%mod;
}
}
int main()
{
ios_base::sync_with_stdio(false);
LL p , a;
while(cin >> p >> a &&p &&a){
if(isPrime(p))cout << "no\n";
else {
LL mod = big_mod(a,p,p);
if(a == mod)cout << "yes\n";
else cout << "no\n";
}
}
return 0;
}
#define sf scanf
#define pf printf
#define LL long long
#define REP(i,MAX) for(int i = 0; i<MAX; i++)
#define MAX 10001
using namespace std;
bool isPrime(LL n)
{
if(n == 1) return false;
if(n == 2) return true;
LL sqr = sqrt(n);
for (LL i = 2; i <= sqr; i++)
{
if(n%i == 0){
return false;
}
}
return true;
}
LL big_mod(LL base, LL power, LL mod)
{
if(power==0) return 1;
else if(power%2==1)
{
LL p1 = base % mod;
LL p2 = (big_mod(base,power-1,mod))%mod;
return (p1*p2)%mod;
}
else if(power%2==0)
{
LL p1 = (big_mod(base,power/2,mod))%mod;
return (p1*p1)%mod;
}
}
int main()
{
ios_base::sync_with_stdio(false);
LL p , a;
while(cin >> p >> a &&p &&a){
if(isPrime(p))cout << "no\n";
else {
LL mod = big_mod(a,p,p);
if(a == mod)cout << "yes\n";
else cout << "no\n";
}
}
return 0;
}
No comments:
Post a Comment