MCP HubMCP Hub
스킬 목록으로 돌아가기

analyze-prime-numbers

pjt222
업데이트됨 2 days ago
3 조회
17
2
17
GitHub에서 보기
테스팅testing

정보

이 스킬은 소수 판별, 인수분해, 분포 계산을 포함한 소수 분석 알고리즘을 제공합니다. 계산적 정수론 작업을 위해 밀러-라빈 검증법, 시행 나눗셈, 에라토스테네스의 체와 같은 방법을 구현합니다. 증명이나 응용 프로그램에서 소수를 확인하거나, 소인수를 찾거나, 소수 목록을 생성해야 할 때 사용하세요.

빠른 설치

Claude Code

추천
기본
npx skills add pjt222/agent-almanac -a claude-code
플러그인 명령대체
/plugin add https://github.com/pjt222/agent-almanac
Git 클론대체
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/analyze-prime-numbers

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

Analyze Prime Numbers

Select + apply right algo: primality, factorization, distribution. Verify computationally + relate to Prime Number Theorem.

Use When

  • Int prime or composite?
  • Complete prime factorization
  • Count/list primes up to bound
  • Verify PNT approx for range
  • Investigate prime props in number-theoretic proof/compute

In

  • Required: Int(s) to analyze, or bound for distribution
  • Required: Task — primality, factorization, distribution
  • Optional: Preferred algo (trial div, Miller-Rabin, Sieve Eratosthenes, Pollard's rho)
  • Optional: Formal proof or computational verdict
  • Optional: Out format (factor tree, prime list, count, table)

Do

Step 1: Determine Task

Classify → 1 of 3 + select algo path:

  1. Primality: Int n, prime?
  2. Factorization: Composite n, complete prime factorization
  3. Distribution: Bound N, analyze primes ≤ N (count, list, gaps, density)

Record task + in values.

Clear classification + in values recorded.

If err: Ambiguous ("analyze 60") → ask clarify primality vs factorization vs distribution. Default factorization for composites + primality confirm suspected primes.

Step 2: Primality Testing (if task = primality)

Test n prime, algo matched to size:

  1. Trivial: n < 2 not prime. n = 2 or 3 prime. n even + n > 2 → composite.

  2. Small n (<10^6): Trial division.

    • Test div all primes p ≤ floor(sqrt(n)).
    • Opt: test 2, then odd 3, 5, 7, ... or 6k +/- 1 wheel.
    • No divisor → prime.
  3. Large n (>=10^6): Miller-Rabin probabilistic.

    • n - 1 = 2^s * d, d odd.
    • Per witness a in {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}:
      • Compute x = a^d mod n.
      • x = 1 or x = n - 1 → pass.
      • Else square x up to s - 1 times. x = n - 1 ever → pass.
      • No pass → composite (a = witness).
    • n < 3.317 * 10^24 → witnesses give deterministic result.
  4. Record verdict: prime or composite + witness/cert.

Small primes (1st 25):

IndexPrimeIndexPrimeIndexPrime
1210291967
2311312071
3512372173
4713412279
51114432383
61315472489
71716532597
8191759
9231861

Definitive (prime/composite) + algo used + witnesses/divisors.

If err: Miller-Rabin "probably prime" + certainty needed → escalate deterministic (AKS or ECPP). Trial div too slow → Miller-Rabin.

Step 3: Factorization (if task = factorization)

Factor n completely → prime power decomposition:

  1. Extract small factors by trial div:

    • Divide 2 as many times as possible, record exponent.
    • Divide odd primes 3, 5, 7, 11, ... up to cutoff (10^4 or sqrt(n) if small).
    • After each div, update n → cofactor.
  2. Cofactor > 1 + <10^12: Continue trial div ≤ sqrt(cofactor).

  3. Cofactor >= 10^12: Pollard's rho.

    • f(x) = x^2 + c (mod n), random c.
    • Floyd cycle: x = f(x), y = f(f(y)).
    • d = gcd(|x - y|, n) each step.
    • 1 < d < n → non-trivial factor. Recurse d + n/d.
    • d = n → retry diff c.
  4. Verify: Multiply all prime factors + exponents = original n. Test each factor primality.

  5. Present: n = p1^a1 * p2^a2 * ... * pk^ak, p1 < p2 < ... < pk.

Algo complexity:

AlgoComplexityBest for
Trial divisionO(sqrt(n))n < 10^12
Pollard's rhoO(n^{1/4}) expectedn up to ~10^18
Quadratic sieveL(n)^{1+o(1)}n up to ~10^50
GNFSL(n)^{(64/9)^{1/3}+o(1)}n > 10^50

Complete prime factorization canonical form + multiplication verified.

If err: Pollard's rho fails after many iters (cycle w/o non-trivial gcd) → try diff c (≥5 attempts). All fail → cofactor may be prime → confirm primality.

Step 4: Distribution Analysis (if task = distribution)

Distribution of primes up to N:

  1. Generate via Sieve Eratosthenes:

    • Bool array size N + 1, true.
    • Set 0 + 1 false (not prime).
    • Per p from 2 to floor(sqrt(N)):
      • Still true → mark multiples p^2, p^2 + p, p^2 + 2p, ... false.
    • Collect indices still true.
  2. Count: pi(N) = primes up to N.

  3. Compare w/ PNT:

    • PNT approx: pi(N) ~ N / ln(N).
    • Logarithmic integral: Li(N) = integral 2 to N of 1/ln(t) dt.
    • Relative err: |pi(N) - N/ln(N)| / pi(N).
  4. Analyze gaps (optional):

    • Gaps between consecutive primes.
    • Max gap, avg gap, twin primes (gap = 2).
    • Avg gap near N ~ ln(N).
  5. Present summary:

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

Count + PNT compare + optional gap analysis.

If err: N too large in-mem sieve (N > 10^9) → segmented sieve processes range in blocks. Count only (no list) → Meissel-Lehmer for pi(N) direct.

Step 5: Verify Computationally

Cross-check via independent method:

  1. Primality: Trial div used → verify quick Miller-Rabin (or vice versa). Known primes → check published tables or OEIS.

  2. Factorization: Multiply factors + confirm = original. Independently test each claimed prime.

  3. Distribution: Spot-check 3-5 numbers from sieve out for primality. Compare pi(N) published values (pi(10^k) k = 1, ..., 9).

Published pi(N):

Npi(N)
104
10025
1,000168
10,0001,229
100,0009,592
10^678,498
10^7664,579
10^85,761,455
10^950,847,534
  1. Doc verification + method + outcome.

All results independently verified no discrepancies.

If err: Verification → discrepancy → re-run w/ extra checks (verbose trial div logging). Common: off-by-one sieve bounds, int overflow modular arithmetic, pseudoprime mistaken prime.

Check

  • Task correctly classified (primality, factorization, distribution)
  • Algo appropriate for in size
  • Trivial cases (n < 2, n = 2, even n) handled pre-general
  • Primality verdicts definitive (not "probably prime" unqualified)
  • Factorizations multiply back to original
  • Every claimed prime factor tested primality
  • Sieve bounds include sqrt(N) coverage
  • PNT compare uses correct formula (N/ln(N) or Li(N))
  • Results verified by independent method or published values
  • Edge cases (n = 0, 1, 2, neg) addressed

Traps

  • Forget n = 1 not prime: Convention — 1 neither prime nor composite. Many algos silently misclassify.

  • Int overflow modular exp: Computing a^d mod n for Miller-Rabin, naive exp overflows. Use modular exp (repeated squaring + mod each step).

  • Sieve off-by-one: Mark composites starting p^2, not 2p. 2p wastes time but correct; p+1 wrong.

  • Pollard's rho cycle w/ d = n: gcd(|x - y|, n) = n → algo found trivial factor. Retry diff c not just starting pt.

  • Carmichael nums fooling Fermat: Nums like 561 = 3 * 11 * 17 pass Fermat primality all coprime bases. Always Miller-Rabin, not plain Fermat.

  • Confuse pi(n) w/ constant pi: Prime counting fn pi(n) + circle constant 3.14159 share notation. Ctx unambiguous.

  • solve-modular-arithmetic — underpins Miller-Rabin + factorization
  • explore-diophantine-equations — factorization prereq for solving many
  • formulate-quantum-problem — Shor's algo for factorization connects primes → quantum

GitHub 저장소

pjt222/agent-almanac
경로: i18n/caveman-ultra/skills/analyze-prime-numbers
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

연관 스킬

evaluating-llms-harness

테스팅

이 Claude Skill은 MMLU, GSM8K를 포함한 60개 이상의 표준화된 학술 과제에서 LLM 성능을 벤치마크하기 위해 lm-evaluation-harness를 실행합니다. 개발자들이 모델 품질을 비교하고, 학습 진행 상황을 추적하거나 학술 결과를 보고할 수 있도록 설계되었습니다. 이 도구는 HuggingFace와 vLLM 모델을 포함한 다양한 백엔드를 지원합니다.

스킬 보기

cloudflare-cron-triggers

테스팅

이 스킬은 cron 표현식을 사용하여 Worker를 스케줄링하기 위한 Cloudflare Cron Triggers 구현에 관한 포괄적인 지식을 제공합니다. 주기적 작업, 유지보수 작업, 자동화된 워크플로우 설정 방법을 다루며, 잘못된 cron 표현식이나 시간대 문제 같은 일반적인 이슈들을 해결하는 방법을 포함합니다. 개발자들은 이를 통해 스케줄된 핸들러 구성, cron 트리거 테스트, Workflows 및 Green Compute와의 연동 작업을 수행할 수 있습니다.

스킬 보기

webapp-testing

테스팅

이 Claude Skill은 Python 스크립트를 통해 로컬 웹 애플리케이션을 테스트하기 위한 Playwright 기반 툴킷을 제공합니다. 프론트엔드 검증, UI 디버깅, 스크린샷 캡처, 로그 확인 기능을 지원하며 서버 라이프사이클을 관리합니다. 브라우저 자동화 작업에 사용하되 컨텍스트 오염을 방지하기 위해 소스 코드를 읽지 않고 스크립트를 직접 실행하세요.

스킬 보기

finishing-a-development-branch

테스팅

이 스킬은 테스트 통과를 확인한 후 체계적인 통합 옵션을 제시하여 개발자가 완성된 작업을 마무리하도록 돕습니다. 구현이 완료된 후 머지, PR 생성, 브랜치 정리와 같은 워크플로우를 안내합니다. 코드가 준비되고 테스트가 완료되었을 때 개발 프로세스를 체계적으로 마무리하기 위해 사용하세요.

스킬 보기