质数判定计算器

Prime Number Checker

Test whether an integer is prime by trial division.

📐 计算公式
素数试除判定(本页代码口径):输入先四舍五入取整;n≥2 且不存在 i(2≤i,i×i≤n)使 n 除以 i 余 0 即判质数,试除上界为 ⌊√n⌋。校验:n 经输入守卫必填且须为合法数值,否则提示并中止。判据:输出「是质数/不是质数」结论并展示 √n 与试除上界;n<2(含 0、1、负数)判非质数。

判断给定正整数是否为质数。

Formula & Standard References

Item Formula / Note Source / Standard
Definition of a prime An integer greater than 1 with no positive divisors other than 1 and itself Euclid, Elements, Book VII, Definition 11
Trial division bound It suffices to test divisors up to sqrt(n) Knuth DE, The Art of Computer Programming, Vol. 2, §4.5.2
Fundamental theorem of arithmetic Every integer greater than 1 has a unique factorization into primes Gauss CF, Disquisitiones Arithmeticae (1801)
Infinitude of primes There are infinitely many primes (Euclid's proof) Euclid, Elements, Book IX, Proposition 20
📌 计算说明
  • 97 是质数。
  • 试除法到 √n 即可。

📚 深度解析:素数判定

💡 常见使用场景

试除法
判断 97 是否为素数:只需试除到 √97≈9.8,即 2,3,5,7。均不能整除,故 97 是素数。1 不是素数,2 是最小的素数也是唯一的偶素数。
合数识别
判断 91:√91≈9.5,试除 7 得 91=7×13,故为合数(容易误以为是素数)。

❓ 常见问题(FAQ)

为什么试除只要到 √n?
若 n 有因子 a×b=n 且 a≤b,则 a≤√n;一旦超过 √n 还没找到因子,更大的因子必然对应更小的已试因子,不可能再出现,所以试到 √n 足够。
1 是素数吗?
不是。素数定义为恰有两个正因子(1 和自身)的数;1 只有一个正因子,被排除在素数之外,这是现代定义的约定。