Modular Arithmetic Deep Dive
141 words
1 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Modular Arithmetic Deep Dive ## Extended Euclidean Algorithm Find $x, y$ such that $ax + by = \gcd(a, b)$: ## Chinese Remainder Theorem System: $x \equiv a_1 \pmod{n_1}$, $x \equiv a_2 \pmod{n_2}$ with $\gcd(n_1, n_2) = 1$. Solution: $x = a_1 M_1 y_1 + a_2 M_2 y_2$ where $M_i = n_1 n_2 / n_i$ and $y_i M_i \equiv 1...

Modular Arithmetic Deep Dive
Extended Euclidean Algorithm
Find x,y such that ax+by=gcd(a,b):
pythondef extended_gcd(a, b): if b == 0: return a, 1, 0 g, x1, y1 = extended_gcd(b, a % b) return g, y1, x1 - (a // b) * y1
Chinese Remainder Theorem
System: x≡a1(modn1), x≡a2(modn2) with gcd(n1,n2)=1.
Solution: x=a1M1y1+a2M2y2 where Mi=n1n2/ni and yiMi≡1(modni).
Example: Solve x≡2(mod3), x≡3(mod5). M1=5, M2=3. y1=5−1≡2(mod3). y2=3−1≡2(mod5). x=2(5)(2)+3(3)(2)=20+18=38≡8(mod15).
Join Discord
PreviousNumber TheoryNextAdvanced Logic & Induction