Prime Number Checker
Test whether an integer is prime by trial division.
📐 计算公式
素数判定(本页代码口径):n 以 BigInt 精确读入,先用小质数试除,再用确定性 Miller–Rabin(底 2、3、5、7、11、13、17、19、23、29、31、37;在 n<3.3×10²⁴ 范围内无伪素数)。校验:n 必须是非负整数,空值、小数、负数报错;为保证精确性 n≤2⁵³−1(9007199254740991),超出安全整数范围直接拒绝。判据:输出「是质数/不是质数」,并展示精确 n、√n 参考值与所用算法;n<2 判非质数。
判断给定正整数是否为质数。
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 即可。