计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
solve-modular-arithmetic【效率与协作】Solve mod arithmetic probs: congruences, systems via CRT, mod inverses, Euler's theorem. Manual + computational. Use → linear congruences, mod inverses, large mod exponentiation, simultaneous congruences (CRT), cyclic groups + discrete log contexts.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Parse congruence systems → extended Euclidean for inverses → CRT for systems → Euler for exponentiation. Verify all by substitution.
Extract math structure.
ID type:
Normalize: Reduce coefs mod respective moduli. a, b, m non-neg, m > 0.
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.
ax = b (mod m) via extended Euclidean.
g = gcd(a, m) via Euclidean:
Solvability: solution iff g | b. Else no solution. Stop.
Reduce: ÷ g → (a/g)x = (b/g) (mod m/g). Now gcd(a/g, m/g) = 1.
Find inverse of a/g mod m/g via extended Euclidean:
Particular sol: x0 = s·(b/g) mod (m/g).
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.
Solve x = a1 (mod m1), x = a2 (mod m2), ..., x = ak (mod mk).
Pairwise coprime check: every pair (mi, mj), gcd(mi, mj) = 1.
M = m1 · m2 · ... · mk (product of all).
Each i, Mi = M/mi (product except mi).
Each i, yi = Mi^{-1} (mod mi) via extended Euclidean (Step 2).
Solution: x = sum(ai · Mi · yi for i = 1..k) mod M.
State: x = [val] (mod M). Unique sol mod M.
Common totients ref:
| 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 |
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.
Eval mod exponentiations | simplify w/ Euler.
Euler: gcd(a, m) = 1 → a^{phi(m)} = 1 (mod m).
Fermat little (special): p prime, gcd(a, p) = 1 → a^{p-1} = 1 (mod p).
Reduce exp: compute a^k (mod m):
a^r (mod m) via repeated squaring (binary exp):
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.
Plug solution back.
Single congruence: a · x mod m = b?
CRT systems: each x = ai (mod mi), x mod mi = ai?
Mod exponentiation: verify w/ 2nd method (direct for small | independent repeated squaring impl).
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.
analyze-prime-numbers — prime fact needed for phi(m) + verify coprimeexplore-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)