#include <iostream>
#include <cstdio>
using namespace std;
typedef long long int LL;
bool Judge_prime(LL n)
{
if(n==1)
return false;
for(LL i=2; i*i<=n; i++)
if(n%i==0)
return false;
return true;
}
LL fast_power(LL p,LL a)
{
LL result=1;
LL mod=p;
while(p>0)
{
if(p&1)
result=(result*a)%mod;
a=(a*a)%mod;
p>>=1;
}
return result;
}
int main()
{
LL p,a;
while(1)
{
scanf("%lld%lld",&p,&a);
if(a==0&&p==0)
break;
if(Judge_prime(p))
printf("no\n");
else
{
LL result=fast_power(p,a);
if(result==a)
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
poj3641—素数判断+快速幂运算
最新推荐文章于 2020-01-11 14:57:34 发布
本文介绍了一种判断素数的方法及快速幂运算的实现。通过简单的C++代码示例,展示了如何判断一个数是否为素数,并利用快速幂运算进行高效计算。适用于初学者了解基本的算法实现。
177

被折叠的 条评论
为什么被折叠?



