Run Code
|
API
|
Code Wall
|
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
Assigment operator (easy)
cvcvcvcvv
СПКИ АП КЭП 2
10 Wizards-DP
nobita's candies problem
Make Bin Tree
Peg Grammar Parser Grasshopper Language
C++ Inheritance Example
Dar
csv parser