Skip to content

Lec 3

Introduction

Theorem 1

For all \(n ≥55\), the number of prime numbers less than \(n\), denoted \(π(n)\) lies in the range

\[\frac{n}{2 + \log n} \leq \pi(n) \leq \frac{n}{-4+\log n}.\]

Algebra Refresher

Fermat's Little Theorem

If \(n\) is prime, then for all \(x \in \mathbb{Z}_{n}^{\ast}\),

\[x^{n-1} \equiv 1 \bmod{n}.\]
Fermat's Little Theorem for Polynomials

\(n\) is prime if, and only if, for all \(a \in \mathbb{Z}_{n}^{\ast}\), the following polynomial equation holds: \((x-a)^n \equiv x^{n} - a \bmod n\).

Algorithms for Checking Primality

Fermat's Test

image.png

它的运行时间取决于计算 \(x^{n-1} \bmod n\), 利用快速幂可以在 \(O(\log n)\) 内求解.

\(n\) 是素数时, 上述算法一定会返回 prime; 当 \(n\) 是合数时, 若 \(n\) 是 Carmichael number, 则返回 prime, 若 \(n\) 不是 Carmichael number, 如果我们选择的 \(x\) 恰好与 \(n\) 互质, 则返回 prime, 否则返回 composite.

Proposition

For any \(n\) that is a composite, but is not a Carmichael number, the probability that the above algorithm outputs "composite" is at least \(1/2\).

Proof

\(n\) 互质的数可以构成 \(\mathbb{Z}_{n}^{+}\) 的子群, 记为 \(H\), 根据 Lagrange's Theorem, \(|H| \mid |\mathbb{Z}_{n}^{+}|\), 因此 \(|H|\) 至多为 \(|\mathbb{Z}_{n}^{+}| / 2 = (n-1) / 2\), 从而选中与 \(n\) 互质的 \(x\) 的概率不会超过 \(1 / 2\).

因为 Carmichael number 远比素数要稀有, 因此上述算法是一个素性测试的 reasonable approach 并被广泛应用.

The Rabin/Miller Algorithm

Miller Rabin.

Fingerprinting

利用 Hashing 检验两个 \(n\)-bit number 是否相等.

image.png

Proposition

If \(A= B\), then \(A≡B \bmod p\) and the algorithm will be correct. We claim that if \(A \not= B\), then for any \(c<n\), if we set \(N= cn\log n\), the probability that the algorithm is correct is at least \(1−3/c\).

Proof

\(A \not= B\), 则算法返回值正确当且仅当 \(p \mid A-B\). 由于 \(A,B \leq 2^{n}\), 因此 \(A-B \leq 2^{n}\), 于是 \(A-B\) 至多有 \(n\) 个不同的素因子. 结合 \(\pi(N) \leq N / (2 + \log N)\), 我们有

\[\begin{aligned}\Pr[failure] &\leq \frac{n}{N / (2+\log N)} = \frac{n(2+\log N)}{cn \log n} \\&= \frac{n(2 + \log c + \log n + \log\log n)}{cn \log n} \\&\leq \frac{1}{c} + \frac{\log c}{c \log n} + \frac{2 + \log \log n}{c \log n} \\&\leq \frac{3}{c}.\end{aligned}\]