Pseudoprime numbers(POJ 3641 快速幂)

时间:2023-03-08 19:37:38
 #include <cstring>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
LL p,res,a;
bool judge_prime(LL k)
{
LL i;
LL u=int(sqrt(k*1.0));
for(i=;i<=u;i++)
{
if(k%i==)
return ;
}
return ;
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%lld%lld",&p,&a))
{
if(p==&&a==)
break;
if(judge_prime(p))
{
printf("no\n");
continue;
}
res=;
LL t=p;
LL w=a;
while(p)
{
if(p&) res=(res*a)%t;
a=(a*a)%t;
p>>=;
}
if(res==w)
printf("yes\n");
else
printf("no\n");
}
}