✅ 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