算法简介 Miller-Rabin算法,这是一个很高效的判断质数的方法,可以在用\(O(logn)\) 的复杂度快速判断一个数是否是质数.它运用了费马小定理和二次探测定理这两个筛质数效率极高的方法. 费马小定理判质数 \(a^{p - 1}\ ≡\ 1\ mod\ p\) 这个定理在 \(p\) 为质数的时候是成立的,所以我们可以如果要判断 \(p\) 是否是质数,可以 \(rand\) 几个 \(a\) 值然后照着这个式子来算,如果算出来不是 \(1\) 那说明 \(p\) 一定不是质数. 但…