快速幂模除m
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include <iostream>
#include<queue>
#include<stack>
#include<string>
using namespace std;
bool judge(long long x)
{
if(x==2) return 1;
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
return false;
}
return true;
}
long long mod(long long a,long long b,long long m)
{
long long ans = 1;
while(b)
{
if(b&1)
{
ans = (ans*a)%m;
b--;
}
b/=2;
a = a*a%m;
}
return ans;
}
int main()
{
long long a,p;
while(cin>>p>>a,!(a==0&&p==0))
{
if(judge(p))
{
cout<<"no\n";
}
else if(mod(a,p,p)==a%p)
{
cout<<"yes\n";
}
else
cout<<"no\n";
}
return 0;
}