Determine whether a number is a Pseudo Prime Number based on. Yes is output only when P is a combination and a ^ P = a (mod P.
Question: miller_rabin prime number test.
#include<cstdio>#include<ctime>#include<cstdlib>using namespace std;#define lint __int64lint modular_exponent ( lint a, lint b, lint n ){ lint ret = 1; for ( ; b; b >>= 1, a = a*a%n ) if ( b & 1 ) ret = ret * a % n; return ret;}int miller_rabin ( int n, int time = 20 ){ if ( n==1 || (n!=2&&!(n%2)) || (n!=3&&!(n%3)) || (n!=5&&!(n%5)) || (n!=7&&!(n%7)) ) return 0; while ( time-- ) { lint m = modular_exponent ( rand()%(n-1) + 1, n-1, n ); if ( m != 1 ) return 0; } return 1;}int main(){ lint p, a; while ( 1 ) { scanf("%I64d%I64d",&p,&a); if ( a == 0 && p == 0 ) break; if ( modular_exponent(a,p,p) == a && !miller_rabin(p) ) printf("yes\n"); else printf("no\n"); } return 0;}