跳到主要内容
uencoder

Test 如果数字是 素数

Primality testing determines 如果数字是 素数. Learn trial division, Miller-Rabin, 和 deterministic tests.

  1. 1

    Primality tests: Trial division (检查 divisibility 通过 primes 上到 sqrt(n) — 慢为 大 n), Fermat (^(n-1) ≡ 1 mod n — fooled 通过 Carmichael numbers), Miller-Rabin (probabilistic, 快, 宽 used), AKS (deterministic, 多项式时间, 但慢 在实践), BPSW (probabilistic, 否 known counterexamples). 为 crypto, Miller-Rabin 具有 40+ rounds 是标准.

  2. 2
    素数检查器 →

    Test 数字为 primality. tool 我们 Miller-Rabin 具有多个 rounds. 为小 numbers (< 2^64), deterministic checks 是 used. 为大 numbers, 结果是 "可能素数" 具有错误概率 < 2^-80 (具有 enough rounds).

  3. 3
    因数分解计算器 →

    如果数字是 composite, 因子它 到 see 其素数 factors. 此 confirms primality 测试结果 — composite 数字将 有 factors 其他 than 1 和 itself. Factoring 是 much harder than primality testing 为大 numbers (basis 的 RSA 安全).

常见问题

是 Miller-Rabin ever 错误?
Miller-Rabin 是 probabilistic — composite 数字有 在最多 1/4 chance 的 passing 每个 round. 具有 40 rounds, 错误概率是 (1/4)^40 ≈ 10^-24. 为 practical purposes, 此是 从不错误. 为 deterministic 结果开 numbers < 3.3×10^24, testing 特定 bases (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37) 是充分.
为什么不 use AKS 测试?
AKS 是 deterministic 和多项式-时间 (theoretically 重要), 但它 是 much slower than Miller-Rabin 在实践. 常量 factors 是大. 为 practical applications, Miller-Rabin 具有 enough rounds 是 preferred — 它是 faster 和错误概率是 negligible.

相关工具