✅ Prime Number Checker

Check whether a number is prime and see its factors or the nearest primes around it.

📐 工作原理与说明
质数判定与因数分解
质数:大于 1 且只有 1 和自身两个因数的整数;n < 2 既非质数也非合数
试除判定:偶数直接排除,奇数 i 从 3 试除至 √n(i ≤ √n),均不能整除则为质数
因数分解:d 从 2 试除至 √x,能整除则反复除去该因子,余数 >1 则为最后一个质因子
合数的最小质因数 = 因数分解结果的首个因子
输入校验:仅接受十进制正整数;≤ 2^53−1 用试除精确分解,更大整数改用 BigInt + Miller-Rabin 判定并做有界试除(余项可能仍可分解)
判断一个数是否为质数。
  • 定义:大于 1 且除 1 与自身外没有其他正因数的整数。
  • 试除法:检查 2 到 √n 之间是否存在因子,复杂度 O(√n)。
  • 优化:先判 2,之后只测奇数;除 2 与 3 外,质数必出现在 6k±1 位置。
  • 大数:通常使用 Miller-Rabin 概率素性检验,确定性判定需选取固定的测试基集合。

Formula & Standard References

Item Formula / Note Source / Standard
Trial division test divisors up to sqrt(n) only Elementary number theory
Miller-Rabin error probability at most 4^-k over k rounds Miller (1976) / Rabin (1980)
Distribution count of primes below n is about n / ln(n) Prime number theorem
⚠️ 使用说明与注意事项

📋 前 20 个质数

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71