目录
Miller-Rabin Primality Test(米勒-罗宾随机素性测试)
Miller-Rabin Primality Test(米勒-罗宾随机素性测试)
静态素数证据表实现(非随机数实现)
函数MillerRabin(LL n, LL a)为一次米勒-罗宾测试结果,true表示测试数n有3/4的把握为素数,false表示n一定是合数。
调用bool isPrime(LL n)来判断数n是否为素数。
bool isPrime(LL n)中的素数表可根据需要增加或减少,增加素数表会使测试的准确率升高,但是测试时间会增长。
#include <iostream>
using namespace std;
typedef long long LL;
LL fastPowMod(LL base, LL p, LL mod) {
LL ret = 1;
base %= mod;
do {
if (p & 1) ret = ret * base % mod;
base = base * base %