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

solve-modular-arithmetic

pjt222
업데이트됨 2 days ago
7 조회
17
2
17
GitHub에서 보기
기타general

정보

이 Claude Skill은 선형 합동식, 모듈러 역원, 큰 수의 모듈러 지수 연산, 그리고 중국 나머지 정리를 이용한 합동식 시스템을 포함한 모듈러 산술 문제를 해결합니다. 확장 유클리드 알고리즘과 오일러 정리를 통한 계산적 검증과 수동 단계별 추론을 결합합니다. 개발자는 순환군, 이산 로그 맥락을 포함한 정수론 작업이나 복잡한 모듈러 표현식을 단순화할 때 이를 사용해야 합니다.

빠른 설치

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/solve-modular-arithmetic

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

문서

Solve Modular Arithmetic

Parse congruence systems → extended Euclidean for inverses → CRT for systems → Euler for exponentiation. Verify all by substitution.

Use When

  • Single linear congruence ax = b (mod m)
  • System of simultaneous congruences (CRT)
  • Mod inverse a^{-1} (mod m)
  • Large mod exp a^k (mod m)
  • Order of element in Z/mZ
  • Cyclic groups, primitive roots, discrete log

In

  • Required: Congruence(s) | mod eqn
  • Optional: Show extended Euclidean steps explicit?
  • Optional: Apply Euler | Fermat?
  • Optional: Find primitive roots | element orders?
  • Optional: Output (step-by-step, compact, proof)

Do

Step 1: Parse System / Eqn

Extract math structure.

  1. ID type:

    • Single linear: ax = b (mod m)
    • System: x = a1 (mod m1), x = a2 (mod m2), ...
    • Mod exp: a^k (mod m)
    • Mod inverse: find a^{-1} (mod m)
  2. Normalize: Reduce coefs mod respective moduli. a, b, m non-neg, m > 0.

  3. Record parsed problem in standard notation.

Got: Clearly parsed + normalized problem, all values reduced.

If err: Ambiguous notation ("solve 3x + 5 = 2 mod 7" → equation or 5=2 mod 7?) → clarify w/ user. Default: mod applies to entire eqn.

Step 2: Solve Single Congruence

ax = b (mod m) via extended Euclidean.

  1. g = gcd(a, m) via Euclidean:

    • Repeated div: m = q1·a + r1, a = q2·r1 + r2, ... until rem = 0
    • Last non-zero rem = gcd(a, m)
  2. Solvability: solution iff g | b. Else no solution. Stop.

  3. Reduce: ÷ g → (a/g)x = (b/g) (mod m/g). Now gcd(a/g, m/g) = 1.

  4. Find inverse of a/g mod m/g via extended Euclidean:

    • Back-sub through Euclidean → 1 = (a/g)·s + (m/g)·t
    • Coef s (reduced mod m/g) = inverse
  5. Particular sol: x0 = s·(b/g) mod (m/g).

  6. General sol: x = x0 + (m/g)·k for k = 0, 1, ..., g-1 → all g incongruent solutions mod m.

Extended Euclidean ex (find 17^{-1} mod 43):

43 = 2*17 + 9
17 = 1*9  + 8
 9 = 1*8  + 1
 8 = 8*1  + 0

Back-substitute:
1 = 9 - 1*8
  = 9 - 1*(17 - 1*9) = 2*9 - 17
  = 2*(43 - 2*17) - 17 = 2*43 - 5*17

So 17*(-5) = 1 (mod 43), i.e., 17^{-1} = -5 = 38 (mod 43).

Got: Complete solution set, or proof no solution exists.

If err: Back-sub wrong result → verify each div step. Most common err: sign mistake in back-sub. Check: a · inverse mod m should = 1.

Step 3: System via CRT

Solve x = a1 (mod m1), x = a2 (mod m2), ..., x = ak (mod mk).

  1. Pairwise coprime check: every pair (mi, mj), gcd(mi, mj) = 1.

    • All coprime → CRT applies directly
    • Some not coprime → check compat: each non-coprime pair, ai = aj (mod gcd(mi, mj)). Compat → reduce via lcm. Incompat → no sol.
  2. M = m1 · m2 · ... · mk (product of all).

  3. Each i, Mi = M/mi (product except mi).

  4. Each i, yi = Mi^{-1} (mod mi) via extended Euclidean (Step 2).

  5. Solution: x = sum(ai · Mi · yi for i = 1..k) mod M.

  6. State: x = [val] (mod M). Unique sol mod M.

Common totients ref:

nphi(n)nphi(n)nphi(n)
21104208
321110248
421242520
541312308
621463612
761584816
841686016
9618610040

Got: Unique sol mod M, or proof of incompat.

If err: CRT result fails verification → check Step 4 inverse calcs. Common: computing Mi^{-1} mod M instead of mod mi. Each inverse is mod individual mi, not product.

Step 4: Apply Euler / Fermat

Eval mod exponentiations | simplify w/ Euler.

  1. Euler: gcd(a, m) = 1 → a^{phi(m)} = 1 (mod m).

    • phi(m): if m = p1^e1 · p2^e2 · ... · pk^ek, phi(m) = m · product((1 - 1/pi) per prime pi | m).
  2. Fermat little (special): p prime, gcd(a, p) = 1 → a^{p-1} = 1 (mod p).

  3. Reduce exp: compute a^k (mod m):

    • r = k mod phi(m)
    • a^k = a^r (mod m)
  4. a^r (mod m) via repeated squaring (binary exp):

    • r in binary: r = b_n · 2^n + ... + b_1 · 2 + b_0
    • result = 1
    • Each bit MSB → LSB: result = result² mod m; bit = 1 → result = result · a mod m
  5. gcd(a, m) > 1: Euler doesn't apply. Factor m + CRT to combine results from prime power moduli, lifting exponent | direct compute.

Got: a^k (mod m) value via exp reduction + repeated squaring.

If err: gcd(a, m) > 1 + result wrong → don't apply Euler. Compute direct | factor m into coprime parts where some coprime to a, solve mod each, recombine via CRT.

Step 5: Verify by Substitution

Plug solution back.

  1. Single congruence: a · x mod m = b?

  2. CRT systems: each x = ai (mod mi), x mod mi = ai?

  3. Mod exponentiation: verify w/ 2nd method (direct for small | independent repeated squaring impl).

  4. Document explicit:

Solution: x = 23
Check 1: 23 mod 3 = 2 = a1. Correct.
Check 2: 23 mod 5 = 3 = a2. Correct.
Check 3: 23 mod 7 = 2 = a3. Correct.
All congruences satisfied.

Got: All eqns verified w/ explicit computation.

If err: Verify fails → trace back. Common: arith mistakes in extended Euclidean, wrong sign in back-sub, forget reduce mod M in final CRT step.

Check

  • Type ID'd (single, system, exp, inverse)
  • All coefs reduced mod respective moduli
  • ax = b (mod m): gcd(a, m) | b checked before solving
  • Extended Euclidean back-sub verified: a · inverse mod m = 1
  • CRT: pairwise coprime verified before
  • CRT non-coprime: compat checked
  • Euler applied only when gcd(a, m) = 1
  • phi(m) from prime factorization, not guessed
  • Repeated squaring uses mod reduction every step (no overflow)
  • Every sol verified by substitution

Traps

  • CRT w/o coprime check: Standard formula needs pairwise coprime. Non-coprime → wrong answer not error. Check gcd(mi, mj) = 1 first.
  • Wrong inverse: Mi^{-1} mod mi (individual), NOT mod M (product). Most common CRT impl err.
  • Euler when gcd(a, m) > 1: a^{phi(m)} = 1 (mod m) needs gcd = 1. Else theorem doesn't apply, result wrong.
  • Sign errs in extended Euclidean back-sub: Track signs each step. Final inverse may be neg → reduce mod m for positive rep.
  • Overflow in mod exp: Even repeated squaring → intermediate products overflow. Reduce mod m after every mult, not just end.
  • Forget multiple solutions: ax = b (mod m), g = gcd(a, m) > 1, g | b → exactly g incongruent solutions mod m, not just one.

  • analyze-prime-numbers — prime fact needed for phi(m) + verify coprime
  • explore-diophantine-equations — linear Diophantine ax + by = c equiv to linear congruence ax = c (mod b)
  • prove-geometric-theorem — mod arith in constructibility proofs (which regular n-gons are constructible)

GitHub 저장소

pjt222/agent-almanac
경로: i18n/caveman-ultra/skills/solve-modular-arithmetic
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

연관 스킬

llamaguard

기타

LlamaGuard는 폭력 및 혐오 발언 등 6가지 안전 범주에서 LLM 입력과 출력을 조정하기 위한 Meta의 70-80억 파라미터 모델입니다. 94-95% 정확도를 제공하며 vLLM, Hugging Face 또는 Amazon SageMaker를 사용해 배포할 수 있습니다. 이 기술을 사용하여 AI 애플리케이션에 콘텐츠 필터링 및 안전 가드레일을 손쉽게 통합하세요.

스킬 보기

cost-optimization

기타

이 Claude Skill은 리소스 적정화, 태깅 전략, 지출 분석을 통해 개발자들이 클라우드 비용을 최적화할 수 있도록 지원합니다. AWS, Azure, GCP에서 클라우드 비용을 절감하고 비용 거버넌스를 구현하기 위한 프레임워크를 제공합니다. 인프라 비용을 분석하거나, 리소스를 적정화하거나, 예산 제약을 충족해야 할 때 사용하세요.

스킬 보기

quantizing-models-bitsandbytes

기타

이 스킬은 bitsandbytes를 사용하여 LLM을 8비트 또는 4비트 정밀도로 양자화하며, 최소한의 정확도 손실로 50-75%의 메모리 감소를 달성합니다. 제한된 GPU 메모리에서 더 큰 모델을 실행하거나 추론을 가속화하는 데 이상적이며, INT8, NF4, FP4와 같은 형식을 지원합니다. 이 스킬은 HuggingFace Transformers와 통합되어 QLoRA 학습 및 8비트 옵티마이저를 가능하게 합니다.

스킬 보기

dispatching-parallel-agents

기타

이 Claude Skill은 3개 이상의 독립적인 문제를 동시에 조사하고 해결하기 위해 다중 에이전트를 배치합니다. 공유 상태나 의존성 없이 해결 가능한 무관련 장애 시나리오에 맞게 설계되었습니다. 핵심 기능은 병렬 문제 해결로, 각 독립 문제 영역마다 하나의 에이전트를 할당하여 효율성을 극대화합니다.

스킬 보기