标签:long name turn amp log prime break def abi
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ULL; int power(ULL a,int k,int mod){ ULL ans=1l; while(k){ if(k&1) ans*=a; a*=a; a%=mod; ans%=mod; k>>=1; } return ans%mod; } bool is_prime(int x){ int n=x-1,a,b=0,k,v; if(x==2||x==3||x==5||x==7||x==11||x==13||x==17)return true; if(!x||x==1||!x&1||!x%3||!x%5||!x%7||!x%11||!x%13||!x%17)return false; while(~n&1){ b++; n>>=1; } a=n; for(int ii=1;ii<=5;ii++){ bool flag=true; k=rand()%(x-1)+1; v=power(k,a,x); if(v==1||v==x-1) continue; for(int i=0;i<=b;i++){ v=(ULL)v*v%x; if(v==x-1){ flag=false; break; } } if(flag) return false; } return true; } int main(){ int k; scanf("%d",&k); if(is_prime(k)) puts("Yes"); else puts("No"); return 0; }
标签:long name turn amp log prime break def abi
原文地址:http://www.cnblogs.com/HC-LittleJian/p/7632565.html