Advertisement
Horikita_Suzune

Untitled

Nov 30th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. int Pow(long long x,int n,long long mod) {
  4.     long long Ans=1,t=x;
  5.     while(n){
  6.         if(n&1)Ans*=t,Ans%=mod;
  7.         t*=t,t%=mod,n>>=1;
  8.     }
  9.     return (int)Ans;
  10. }
  11. int JudgePrime(int n) {
  12.     if(n==2||n==3)return 1;
  13.     else if(n==1)return 0;
  14.     else if(!(n&1))return 0;
  15.     int a,x,t;
  16.     for(a=0;a<2;a++){
  17.         x=rand()%(n-4)+2;
  18.         t=Pow(x,n-1,n);
  19.         if(t!=1)return 0;
  20.     }
  21.     return 1;
  22. }
  23. //a007 AC code
  24. //using Miller Rabin Algorithm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement