技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
analyze-prime-numbers【数据与研究】Analyze prime numbers using primality tests, factorization algorithms, prime distribution analysis, and sieve methods. Covers trial division, Miller-Rabin, Sieve of Eratosthenes, and the Prime Number Theorem. Use when determining whether an integer is prime or composite, finding prime factorizations, counting or listing primes up to a bound, or inves…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
藉為當下任務擇宜之演算法(質性測試、整數分解或質數分佈分析),析質數。以計算驗結果並將發現繫於質數定理。
將請求歸為三類之一並擇宜之演算路徑。
記任務類型與輸入值。
預期: 清晰之分類,輸入值已記。
失敗時: 若輸入曖昧(如「析 60」),請使用者澄清欲質性測試、分解或分佈分析。對合數預設為分解,對疑似質數預設為質性確認。
以合於 n 之大小之演算法測試 n 是否為質。
小質數參考(前 25):
| Index | Prime | Index | Prime | Index | Prime |
|---|---|---|---|---|---|
| 1 | 2 | 10 | 29 | 19 | 67 |
| 2 | 3 | 11 | 31 | 20 | 71 |
| 3 | 5 | 12 | 37 | 21 | 73 |
| 4 | 7 | 13 | 41 | 22 | 79 |
| 5 | 11 | 14 | 43 | 23 | 83 |
| 6 | 13 | 15 | 47 | 24 | 89 |
| 7 | 17 | 16 | 53 | 25 | 97 |
| 8 | 19 | 17 | 59 | ||
| 9 | 23 | 18 | 61 |
預期: 確定之答(質或合),附所用演算法與所尋見證或除數。
失敗時: 若 Miller-Rabin 報「可能為質」而需確定,升至確定性測試(如 AKS 或 ECPP)。對試除,若計算過慢,改 Miller-Rabin。
將 n 完整分解為其質冪分解。
演算法繁複度註:
| Algorithm | Complexity | Best for |
|---|---|---|
| Trial division | O(sqrt(n)) | n < 10^12 |
| Pollard's rho | O(n^{1/4}) expected | n up to ~10^18 |
| Quadratic sieve | L(n)^{1+o(1)} | n up to ~10^50 |
| GNFS | L(n)^{(64/9)^{1/3}+o(1)} | n > 10^50 |
預期: 規範形之完整質因式分解,由乘法驗。
失敗時: 若 Pollard rho 多迭仍無因子(已偵循環而無非瑣 gcd),試不同之 c 值(至少 5 試)。若皆失,餘因子或為質——以質性測試確認。
析至給定界 N 之質數分佈。
Bound N: 1,000,000
pi(N): 78,498
N/ln(N): 72,382
Li(N): 78,628
Relative error (N/ln(N)): 7.79%
Relative error (Li(N)): 0.17%
Max prime gap: 148 (between 492113 and 492227)
Twin primes: 8,169 pairs
預期: 質數計數附 PNT 比對與選擇性間距分析。
失敗時: 若 N 過大不能於記憶體中篩(N > 10^9),用以區塊處理範圍之分段篩。若僅需計(非列),用 Meissel-Lehmer 演算法直接得 pi(N)。
以獨立之計算法交叉查一切結果。
已發表之 pi(N) 值:
| N | pi(N) |
|---|---|
| 10 | 4 |
| 100 | 25 |
| 1,000 | 168 |
| 10,000 | 1,229 |
| 100,000 | 9,592 |
| 10^6 | 78,498 |
| 10^7 | 664,579 |
| 10^8 | 5,761,455 |
| 10^9 | 50,847,534 |
預期: 一切結果獨立驗,無歧異。
失敗時: 若驗揭歧異,重行原計算並啟額外查(如冗詳之試除記錄)。最常見之誤為篩界差一、模算術中整數溢位、將偽質誤為真質。
遺 n = 1 非質:按慣例,1 既非質亦非合。許多演算法默默誤類之
模冪中之整數溢位:為 Miller-Rabin 計 a^d mod n 時,樸素冪算溢位。用模冪算(每步取模之重複平方)
篩之差一誤:篩須自 p^2 而非自 2p 標合數。自 2p 起費時然正確;自 p+1 起則誤
Pollard rho 之 d = n 循環:若 gcd(|x - y|, n) = n,演算法尋得瑣因子。以不同多項式常 c 重試,非僅以不同起點
Carmichael 數騙 Fermat 測試:561 = 3 * 11 * 17 等數對一切互質基通 Fermat 質性測試。恆用 Miller-Rabin 而非純 Fermat
混 pi(n) 與常數 pi:質數計數函式 pi(n) 與圓常數 3.14159… 共用記號。情境須無歧
solve-modular-arithmetic — 模算術為 Miller-Rabin 與許多分解法之基explore-diophantine-equations — 質因式分解為解許多 Diophantine 方程之先決formulate-quantum-problem — Shor 整數分解演算法將質數繫於量子計算