Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Primality test Fermat primality test
//g++ 5.4.0 Primality test Fermat primality test #include <bits/stdc++.h> using namespace std; int binPower(int a, int b , int p){ int res = 1; a = a%p; while(b>0){ if(b&1) res = (res * a) %p; a = a*a%p; b>>=1; } return res%p; } bool checkPrime(int n){ for(int i=0;i<10;i++){ int a = 2 + rand()%(n-3); if(binPower(a,n-1,n)!=1){ return false; } } return true; } int main() { if(checkPrime(56)) cout<<"yes"; else cout<<"No"; return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Random Vector Generator
Const Return Test
005#
Wave Sort
2
hey
nobita's candies problem
base and derr con
proga2
Synchro#2
Please log in to post a comment.