您的位置:首页 > 其它

poj 3641

2015-11-04 20:34 197 查看
根据题目的定义来做,考quick_mod的应用,比较水

#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

const int maxn = 1000005;

typedef long long LL;

vector<int>G[maxn];

bool prim(LL n)
{
int  t = (int)sqrt(n)+1;
if( n == 2 || n == 1) return 1;
LL i;
for(i=2;i<=t;i++){
if(n%i == 0){
return 0;
break;
}
}
return 1;
}

LL quick_mod(LL a,LL b,LL m)
{
LL ans = 1;
while(b){
if(b&1){
ans = (ans*a)%m;
}
b>>=1;
a = a*a%m;
}
return ans;
}

int main()
{
LL a,n,p,b;
while(cin>>p>>a&&(a+p)){
if(prim(p)) puts("no");
else{
LL ans = 1;
ans = quick_mod(a,p,p);
if(ans == a) puts("yes");
else puts("no");
}
}

return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: