快速幂入门。。。
wa一次是因为没认识到p不能为质数
/*
author:hdsdogge
begin:
end:
cost:
*/
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<list>
#include <sstream>
#include<ctype.h>
using namespace std;
const int maxn=100+10;
typedef pair<int,int> P;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
int T,n,m;
ll a,p;
bool is_pirme(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0)
return false;
}
return true;
}
int main() {
//freopen("test", "r", stdin);
//freopen("out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(0);
while (cin >> p >> a && a + p) {
ll ans = 1;
ll x = a;
ll p1 = p;
while (p1 > 0) {
if (p1 & 1)
ans = (ans * x) % p;
x = (x * x) % p;
p1 >>= 1;
}
if (ans == a && !is_pirme(p)) {
cout << "yes" << endl;
}
else
cout << "no" << endl;
}
return 0;
}
原文地址:https://www.cnblogs.com/hdsdogge/p/9349743.html
时间: 2024-11-13 10:47:54