Unit 3: Number Theory-III
I. Orientation: Congruences and Modular Arithmetic
Congruence, introduced by Gauss (Disquisitiones Arithmeticae, 1801), is the language for reasoning about remainders. This unit builds every technique below on a single relation: two integers are equivalent when they leave the same remainder on division by a fixed modulus.
- Definition of congruence: For integers
a,band a positive integerm, we writea ≡ b (mod m)ifm | (a − b). Equivalently,aandbhave the same remainder when divided bym. - Residue classes: The modulus
mpartitions the integers intomdisjoint classes[0], [1], …, [m−1]; the set{0,1,…,m−1}is the complete set of least non-negative residues. - Arithmetic conventions: If
a ≡ b (mod m)andc ≡ d (mod m), thena+c ≡ b+d,a−c ≡ b−d, andac ≡ bd (mod m). Addition, subtraction and multiplication respect classes. - Cancellation caveat: Division is not free —
ac ≡ bc (mod m)impliesa ≡ b (mod m/gcd(c,m)), not necessarilya ≡ b (mod m). - Key tool:
gcdand the Extended Euclidean Algorithm, which yields integersx, ywithax + by = gcd(a,b), underpin inversion and solvability throughout.
II. Linear Congruences
Solving ax ≡ b (mod m) and modular inverses
A linear congruence is the modular analogue of a linear equation; its solvability is governed entirely by a gcd.
A. Statement and solvability condition
The congruence ax ≡ b (mod m) seeks all integers x satisfying the relation.
- Solvability criterion: Let
d = gcd(a, m). A solution exists iffd | b. - Number of solutions: If
d | b, there are exactlydincongruent solutions modulom. - Reason:
ax ≡ b (mod m)is equivalent to the linear Diophantine equationax − my = b, solvable precisely whend | b.
B. The modular inverse
When gcd(a, m) = 1, a has a unique inverse a⁻¹ with a·a⁻¹ ≡ 1 (mod m).
- Existence: The inverse exists iff
gcd(a, m) = 1. - Computation: Extended Euclidean Algorithm gives
ax + my = 1, sox ≡ a⁻¹ (mod m). - Use: Multiply
ax ≡ bbya⁻¹to get the unique solutionx ≡ a⁻¹ b (mod m).
C. Worked example and limitations
Solving 3x ≡ 4 (mod 7):
gcd(3,7)=1 → unique solution
3·5 = 15 ≡ 1 (mod 7) → 3⁻¹ ≡ 5
x ≡ 5·4 = 20 ≡ 6 (mod 7)- Verification:
3·6 = 18 ≡ 4 (mod 7). ✓ - Limitation: When
d = gcd(a,m) > 1andd ∤ b, no solution exists (e.g.2x ≡ 3 (mod 4)is unsolvable sincegcd=2 ∤ 3).
III. The Chinese Remainder Theorem
Reconstructing an integer from its remainders
The CRT solves a system of simultaneous congruences with pairwise coprime moduli, guaranteeing a unique answer within the product modulus.
A. Statement and conditions
Given congruences with pairwise coprime moduli, a unique joint solution exists.
- System:
x ≡ a₁ (mod m₁),x ≡ a₂ (mod m₂), …,x ≡ aₙ (mod mₙ). - Condition: The moduli are pairwise coprime:
gcd(mᵢ, mⱼ) = 1fori ≠ j. - Conclusion: There is a unique solution modulo
M = m₁m₂⋯mₙ.
B. The Chinese remainder theorem — constructive method
The proof is constructive and gives a formula.
M = m₁·m₂·…·mₙ
Mₖ = M / mₖ
yₖ ≡ Mₖ⁻¹ (mod mₖ) (inverse of Mₖ modulo mₖ)
x ≡ Σ aₖ·Mₖ·yₖ (mod M)- Symbols:
Mₖis the product of all moduli exceptmₖ;yₖits inverse modmₖ. - Why it works:
Mₖ ≡ 0 (mod mⱼ)forj ≠ k, so each term contributes only to its own congruence.
C. Worked example
Solve x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7):
M = 105, M₁=35, M₂=21, M₃=15
35 ≡ 2 (mod 3) → y₁ = 2 (2·2=4≡1)
21 ≡ 1 (mod 5) → y₂ = 1
15 ≡ 1 (mod 7) → y₃ = 1
x = 2·35·2 + 3·21·1 + 2·15·1 = 140+63+30 = 233 ≡ 23 (mod 105)- Check:
23 = 3·7+2(≡2 mod 3),23 = 5·4+3(≡3 mod 5),23 = 7·3+2(≡2 mod 7). ✓
IV. Computer Arithmetic with Large Integers
Representing and computing with numbers beyond machine word size
Cryptography needs integers of hundreds of digits, so numbers are held as arrays of digits in a large base and manipulated by algorithms whose cost is tracked carefully.
A. Representation of large integers
A big integer is stored positionally in a base matched to the machine word.
- Base choice: Digits taken base
b = 2³²or2⁶⁴so each "digit" fits one register; the value isΣ dᵢ bⁱ. - Storage: An array
(d₀, d₁, …, d_{n−1})plus a sign flag; lengthngrows with the number's size.
B. CRT-based and modular representation
The CRT lets a large integer be represented by its residues, parallelising arithmetic.
- Residue system: Pick coprime moduli
m₁,…,mₙ; representxby(x mod m₁, …, x mod mₖ). - Benefit: Addition and multiplication act componentwise, with no carries between components — ideal for parallel hardware.
- Recovery: The original
x < Mis reconstructed via the CRT formula in Section III.B.
C. Cost of the basic operations
Efficiency is measured in bit operations as a function of digit length n.
- Addition/subtraction:
O(n)— digitwise with carry propagation. - Schoolbook multiplication:
O(n²); Karatsuba reduces this to aboutO(n^1.585). - Modular exponentiation: Computed by repeated squaring, reducing mod
mat each step so operands never exceedm²:
result = 1; base = a mod m
while e > 0:
if e is odd: result = (result * base) mod m
base = (base * base) mod m
e = e >> 1 # e ← ⌊e/2⌋- Bound: Exponentiation
aᵉ mod musesO(log e)multiplications — essential for RSA wheree, mare enormous.
V. Fermat's Little Theorem
A prime modulus forces a power identity
Fermat's Little Theorem (Pierre de Fermat, 1640) states a fundamental relation between any integer and a prime modulus, and is the engine behind fast primality testing.
A. Statement and conditions
- Primary form: If
pis prime andp ∤ a, thena^{p−1} ≡ 1 (mod p). - Universal form: For any integer
a,aᵖ ≡ a (mod p)(no coprimality needed). - Consequence: For
p ∤ a, the inverse isa⁻¹ ≡ a^{p−2} (mod p).
B. Worked example
Compute 3^100 mod 7:
FLT: 3⁶ ≡ 1 (mod 7)
100 = 6·16 + 4
3^100 = (3⁶)^16 · 3⁴ ≡ 1·3⁴ (mod 7)
3⁴ = 81 ≡ 4 (mod 7)- Result:
3^100 ≡ 4 (mod 7); the theorem collapses a huge exponent to a tiny one.
C. Applications and limitations
- Fermat primality test: If
a^{n−1} ≢ 1 (mod n)for somea, thennis composite (proof of compositeness). - Carmichael numbers: The converse fails — composites like
561 = 3·11·17satisfya^{n−1} ≡ 1for all coprimea, so passing the test does not prove primality. - Relation to Euler: FLT is the special case
φ(p) = p−1of Euler's theorema^{φ(m)} ≡ 1 (mod m)forgcd(a,m)=1.
VI. Applications of Congruences
Everyday and cryptographic uses of modular arithmetic
Congruences appear wherever data must be mapped, distributed, checked or protected using a fixed modulus.
A. Hashing and pseudorandom generation
- Hash functions: A key
kmaps to sloth(k) = k mod m, distributing records acrossmbuckets; a primemspreads keys evenly. - Linear congruential generator:
x_{n+1} = (a·xₙ + c) mod mproduces pseudorandom sequences; period quality depends on choosinga, c, m(e.g.m = 2³¹).
B. Check digits and error detection
- ISBN-10: Digits satisfy
Σ i·dᵢ ≡ 0 (mod 11); the check digitd₁₀makes the weighted sum divisible by 11, catching single-digit and transposition errors. - UPC/EAN: A weighted sum taken
mod 10validates barcodes.
C. Cryptography
- Caesar/affine ciphers: Encryption
E(x) = (ax + b) mod 26; decryption needsa⁻¹ (mod 26), sogcd(a,26)=1. - RSA: With
n = pq, public exponente, privatedwhereed ≡ 1 (mod φ(n)): encryptc = mᵉ mod n, decryptm = c^d mod n. Correctness rests on Fermat/Euler theorems; security rests on the hardness of factoringn. - Diffie–Hellman: Shared secret from
g^{ab} mod p, relying on the difficulty of the discrete logarithm modulo a large prime.
D. Calendars and scheduling
- Day-of-week arithmetic: Weekday cycles are computed
mod 7; e.g. 100 days after a Monday is(0 + 100) mod 7 = 2, a Wednesday. - Zeller-type formulas: Combine
mod 7andmod 12reductions to map any date to a weekday, illustrating congruences over multiple moduli.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →