Miller_Rabin素数测试

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define inf 0x3f3f3f3f
#define eps 1e-8
#define LL long long 
#define ull unsigned long long
#define MP make_pair
#define For( i, x, y ) for( int i = ( x ); i < ( y ); ++i )
#define mxn 300200
LL prime[6] = { 2, 3, 5, 233, 331 };
LL qpow( LL a, LL n, LL mod ) {
	if( n == 1 )
		return a;
	if( n == 0 )
		return 1;
	LL ret = qpow( a, n / 2, mod );
	ret = ( ret * ret ) % mod;
	if( n & 1 )
		ret = ( ret * a ) % mod;
	return ret;
}
bool Miller_Rabin( LL p ) {
	if( p < 2 )
		return 0;
	if( p != 2 && p % 2 == 0 )
		return 0;
	LL s = p - 1;
	while( ! ( s & 1 ) ) s >>= 1;
	For( i, 0, 5 ) {
		if( p == prime[i] )
			return 1;
		LL t = s, m = qpow( prime[i], s, p );
		while( t != p - 1 && m != 1 && m != p - 1 ) {
			m = ( m * m ) % p;
			t <<= 1;
		}
		if( m != p - 1 && ! ( t & 1 ) )
			return 0;
	}
	return 1;
}
int main() {
	return 0;
}

你可能感兴趣的:(Miller_Rabin素数测试)