executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
solve-modular-arithmeticSolve modular arithmetic problems including congruences, systems via the Chinese Remainder Theorem, modular inverses, and Euler's theorem applications. Covers both manual and computational approaches. Use when solving linear congruences, computing modular inverses, evaluating large modular exponentiations, working with simultaneous congruences (CRT), or ope…
Independent GitHub snapshot · Automated classification · Original documentation governs
解同餘——析同餘系、用擴 Euclid 求逆、用中國餘剩定理(CRT)解同時、用 Euler 定理為模冪。各解必代驗。
由問取數構:
識類:
規:諸係模其模而簡。確 a、b、m 為非負整、m > 0
記 析問於標號
得:明析、規之模問、諸值已簡。
敗:號歧(如「解 3x + 5 = 2 mod 7」或為 3x + 5 = 2 (mod 7) 或 3x + (5 = 2 mod 7))→詢用。默以模施全方。
以擴 Euclid 解 ax = b (mod m)。
計 g = gcd(a, m) 用 Euclid 算:
察可解:ax = b (mod m) 有解當且唯當 g | b
減:兩除以 g 得 (a/g)x = (b/g) (mod m/g)。今 gcd(a/g, m/g) = 1
求 a/g 模 m/g 之逆 用擴 Euclid:
計特解:x0 = s * (b/g) mod (m/g)
書通解:x = x0 + (m/g)*k 為 k = 0, 1, ..., g - 1 給諸 g 模 m 不同餘解
擴 Euclid 例(求 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).
得:同餘之全解集、或無解之證。
敗:擴 Euclid 反代生誤果→驗各除步。最常為反代中號誤。察:a * 逆 mod m 當為 1。
解 x = a1 (mod m1), x = a2 (mod m2), ..., x = ak (mod mk)。
驗對對互質:各對 (mi, mj) 驗 gcd(mi, mj) = 1
計 M = m1 * m2 * ... * mk(諸模之積)
各 i 計 Mi = M / mi(除 mi 外諸模之積)
各 i 求 yi = Mi^{-1} (mod mi) 用步二之擴 Euclid
計解:x = sum(ai * Mi * yi for i = 1..k) mod M
陳果:x = [值] (mod M)。為模 M 之獨解
常 totient 參:
| n | phi(n) | n | phi(n) | n | phi(n) |
|---|---|---|---|---|---|
| 2 | 1 | 10 | 4 | 20 | 8 |
| 3 | 2 | 11 | 10 | 24 | 8 |
| 4 | 2 | 12 | 4 | 25 | 20 |
| 5 | 4 | 13 | 12 | 30 | 8 |
| 6 | 2 | 14 | 6 | 36 | 12 |
| 7 | 6 | 15 | 8 | 48 | 16 |
| 8 | 4 | 16 | 8 | 60 | 16 |
| 9 | 6 | 18 | 6 | 100 | 40 |
得:模 M 之獨解、或不容之證。
敗:CRT 計生敗驗果→察步四模逆計。常誤為計 Mi^{-1} mod M 而非 Mi^{-1} mod mi。各逆於個模、非積。
以 Euler 定理評模冪或簡。
Euler 定理:若 gcd(a, m) = 1、則 a^{phi(m)} = 1 (mod m)
Fermat 小定理(特例):p 素、gcd(a, p) = 1→a^{p-1} = 1 (mod p)
減冪:計 a^k (mod m):
計 a^r (mod m) 用復方(二進冪):
gcd(a, m) > 1 之例:Euler 不直施。析 m 而以 CRT 合素冪模之果、用提冪或直計
得:a^k (mod m) 之值、以冪減與復方計。
敗:gcd(a, m) > 1 而果似誤→勿施 Euler。直計或析 m 為互質部、至少某部與 a 互質、各部解、以 CRT 合。
各解代回原方。
單同餘:計 a * x mod m 驗為 b
CRT 系:各 x = ai (mod mi) 驗 x mod mi = ai
模冪:可則用次法驗(如小值直計、或獨復方)
明文驗:
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.
得:諸原方明驗示計。
敗:驗敗→自過追計誤。常源:擴 Euclid 算誤、反代號誤、忘 CRT 末步簡 mod M。
analyze-prime-numbers — 素析需於計 phi(m) 與驗互質explore-diophantine-equations — 線 Diophantine ax + by = c 等於線同餘 ax = c (mod b)prove-geometric-theorem — 模算現於可作證(如何正 n 邊可作)