技能创建器
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 快照 · 自动分类 · 以原作者文档为准
Analyze prime numbers. Select and apply appropriate algorithm for task at hand: primality testing, integer factorization, or prime distribution analysis. Verify results computationally. Relate findings to Prime Number Theorem.
Classify request into one of three categories. Select appropriate algorithmic path.
Record task type and input value(s).
Got: Clear classification with input values recorded.
If fail: Input ambiguous (e.g., "analyze 60")? Ask user to clarify whether they want primality test, factorization, or distribution analysis. Default to factorization for composite numbers and primality confirmation for suspected primes.
Test whether n prime using algorithm matched to size of n.
Handle trivial cases: n < 2 not prime. n = 2 or n = 3 prime. n even and n > 2? Composite.
Small n (n < 10^6): Use trial division.
Large n (n >= 10^6): Use Miller-Rabin probabilistic test.
Record verdict: prime or composite, with witness or certificate.
Small primes reference (first 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 |
Got: Definitive answer (prime or composite) with algorithm used and any witnesses or divisors found.
If fail: Miller-Rabin reports "probably prime" but certainty required? Escalate to deterministic test (e.g., AKS or ECPP). For trial division, computation too slow? Switch to Miller-Rabin.
Factor n complete into its prime power decomposition.
Extract small factors by trial division:
Cofactor > 1 and cofactor < 10^12: Continue trial division up to sqrt(cofactor).
Cofactor > 1 and cofactor >= 10^12: Apply Pollard's rho algorithm.
Verify: Multiply all found prime factors (with exponents) and confirm product equals original n. Test each factor for primality.
Present result in standard form: n = p1^a1 * p2^a2 * ... * pk^ak with p1 < p2 < ... < pk.
Algorithm complexity notes:
| 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 |
Got: Complete prime factorization in canonical form, verified by multiplication.
If fail: Pollard's rho fails to find factor after many iterations (cycle detected without non-trivial gcd)? Try different values of c (at least 5 attempts). All fail? Cofactor may be prime -- confirm with primality test.
Analyze distribution of primes up to given bound N.
Generate primes using Sieve of Eratosthenes:
Count primes: Compute pi(N) = number of primes up to N.
Compare with Prime Number Theorem:
Analyze prime gaps (optional):
Present findings in summary table:
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
Got: Count of primes with PNT comparison and optional gap analysis.
If fail: N too large for in-memory sieving (N > 10^9)? Use segmented sieve that processes range in blocks. Only count needed (not list)? Use Meissel-Lehmer algorithm for pi(N) directly.
Cross-check all results using independent computation method.
For primality: Trial division used? Verify with quick Miller-Rabin pass (or vice versa). For known primes, check against published prime tables or OEIS sequences.
For factorization: Multiply all factors and confirm equality with original input. Independently test each claimed prime factor for primality.
For distribution: Spot-check by testing 3-5 individual numbers from sieve output for primality. Compare pi(N) against published values for standard benchmarks (pi(10^k) for k = 1, ..., 9).
Published values of 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 |
Got: All results independently verified with no discrepancies.
If fail: Verification reveals discrepancy? Re-run original computation with extra checks enabled (e.g., verbose trial division logging). Most common errors: off-by-one in sieve bounds, integer overflow in modular arithmetic, mistaking pseudoprime for prime.
Forgetting n = 1 not prime: By convention, 1 neither prime nor composite. Many algorithms silently misclassify it.
Integer overflow in modular exponentiation: When computing a^d mod n for Miller-Rabin, naive exponentiation overflows. Use modular exponentiation (repeated squaring with mod at each step).
Sieve off-by-one errors: Sieve must mark composites starting from p^2, not from 2p. Starting from 2p wastes time but correct; starting from p+1 wrong.
Pollard's rho cycle with d = n: gcd(|x - y|, n) = n? Algorithm has found trivial factor. Retry with different polynomial constant c, not just different starting point.
Carmichael numbers fooling Fermat's test: Numbers like 561 = 3 * 11 * 17 pass Fermat's primality test for all coprime bases. Always use Miller-Rabin, not plain Fermat.
Confusing pi(n) with constant pi: Prime counting function pi(n) and circle constant 3.14159... share notation. Context must be unambiguous.
solve-modular-arithmetic -- Modular arithmetic underpins Miller-Rabin and many factorization methodsexplore-diophantine-equations -- Prime factorization is prerequisite for solving many Diophantine equationsformulate-quantum-problem -- Shor's algorithm for integer factorization connects primes to quantum computing