#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
long long qmod(int a, int b, int p) {
long long res = 1;
long long term = a%p;
while(b) {
if(b&1){
res = (res*term)%p;
}
term = (term*term)%p;
b >>= 1;
}
return res;
}
bool is_prime(long long n) {
int i;
for(i = 0; i < 100; ++i) {
if(qmod(1+rand()%(n-1),n-1, n) != 1)
break;
}
if(i < 100)
return false;
else
return true;
}
int main(void) {
int n;
while(cin >> n) {
if(is_prime(n))
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
C++实现费马小定理素数测试
最新推荐文章于 2024-01-28 17:10:53 发布