Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Ballin primality test
//g++ 5.4.0 Primality test Ballin primality test #include <bits/stdc++.h> using namespace std; typedef uint64_t ui; ui binPower(ui a, ui b , ui p){ ui 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 checkComp(ui n , ui a , int d, int s){ int status = binPower(a,n-1,n); if(status==1 || status == n-1) return false; for(int r=0;r<s;r++){ a = (a*a)%n; if(a==n-1) return false; } return true; } bool checkComposite(ui n){ if (n < 4) return n == 2 || n == 3; ui d = n-1; int s = 0; while(d&1==0){ d>>=1; s++; } for(ui a=0;a<10;a++){ if(checkComp(n,a,d,s)==false){ return false; } } return true; } int main() { if(checkComposite(28)) cout<<"No"; else cout<<"Yes"; return 0; }
run
|
edit
|
history
|
help
0
stl_sizeof
Stock buy/sell
4C test
Matrix rotation
shared_ptr deleter
Teatime Snack
Decimal to Binary
CPP - Arrays - Ex.2 - Solution
რიცხვები დაფაზა~ფინალური
DP Optimization another kind