poj3641
问p是不是伪素数。伪素数条件:①p不是素数。②
//164k, 16ms
#include <iostream>
using namespace std;
typedef long long ll;
bool testPrime(ll x) {
for (ll i=2; i*i<=x; i++)
if(x % i == 0)
return false;
return true;
}
//快速幂运算
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while(n > 0) {
if(n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll a, p;
int main() {
freopen("in.txt", "r", stdin);
while(~scanf("%lld%lld", &p, &a) && a && p) {
if(testPrime(p)) {
printf("no\n");
} else {
if(mod_pow(a, p, p) == a % p)
printf("yes\n");
else
printf("no\n");
}
}
fclose(stdin);
return 0;
}