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 即可。