Advanced Number Theory

Study Sheet

Advanced Number Theory

CRT, orders, and totients

Systems of Congruences

Tip
Chinese Remainder Theorem

If the moduli are pairwise coprime, a system x≡ai(modmi)x\equiv a_i\pmod{m_i} has a unique solution modulo ∏mi\prod m_i.

In plain terms. Several "remainder" conditions with no shared factors always combine into a single condition — one remainder mod the product.

Example. x≡2(mod3)x\equiv 2\pmod 3 and x≡3(mod5)x\equiv 3\pmod 5 give x≡8(mod15)x\equiv 8\pmod{15} (check: 8=2⋅3+28 = 2\cdot3+2 and 8=5+38 = 5+3).

Why it works. For coprime mm and nn, look at the mnmn numbers 0,1,…,mn−10, 1, \dots, mn - 1 and record each one's pair of remainders (mod mm, mod nn). Two numbers with the same pair differ by a multiple of both mm and nn, hence of mnmn, so no pair is repeated. There are exactly mnmn possible pairs, so every pair occurs exactly once: each system has a solution, and it is unique mod mnmn. To FIND it, solve one congruence, substitute the general solution into the next, and repeat.

Example
Worked: three moduli

Find the least positive integer NN with N≡3(mod7)N \equiv 3 \pmod 7, N≡5(mod11)N \equiv 5 \pmod{11} and N≡2(mod13)N \equiv 2 \pmod{13}.

Spotting it. Pairwise coprime moduli with product 10011001: there is exactly one answer below 10011001, and substitution finds it one congruence at a time.

Step 1. N=7a+3N = 7a + 3. Mod 1111: 7a≡27a \equiv 2. Since 7⋅8=56≡1(mod11)7 \cdot 8 = 56 \equiv 1 \pmod{11}, a≡16≡5a \equiv 16 \equiv 5, so N≡7⋅5+3=38(mod77)N \equiv 7 \cdot 5 + 3 = 38 \pmod{77}.

Step 2. N=77b+38N = 77b + 38. Mod 1313: 77≡−177 \equiv -1 and 38≡1238 \equiv 12, so −b+12≡2-b + 12 \equiv 2 and b≡10(mod13)b \equiv 10 \pmod{13}.

Step 3. N=770+38=808N = 770 + 38 = 808. Check: 808=7⋅115+3=11⋅73+5=13⋅62+2808 = 7 \cdot 115 + 3 = 11 \cdot 73 + 5 = 13 \cdot 62 + 2 ✓

Example
Worked: the last three digits of a power

Find the remainder when 320263^{2026} is divided by 10001000.

Spotting it. Mod 10001000 is two easier problems: mod 88 and mod 125125, which are coprime. Solve each, then glue with CRT.

Step 1. Mod 88: 32=9≡13^2 = 9 \equiv 1, so 32026≡13^{2026} \equiv 1.

Step 2. Mod 125125: φ(125)=100\varphi(125) = 100, so 32026≡3263^{2026} \equiv 3^{26}. Build it up: 35=243≡−73^5 = 243 \equiv -7, 310≡493^{10} \equiv 49, 320≡492=2401≡263^{20} \equiv 49^2 = 2401 \equiv 26, 325≡26⋅(−7)=−182≡683^{25} \equiv 26 \cdot (-7) = -182 \equiv 68, and 326≡204≡793^{26} \equiv 204 \equiv 79.

Step 3. Find x≡79(mod125)x \equiv 79 \pmod{125} with x≡1(mod8)x \equiv 1 \pmod 8: try 79,204,32979, 204, 329; the remainders mod 88 are 7,4,17, 4, 1. So the answer is 329329.

Side note
Where it goes wrong

Applying CRT to moduli that share a factor. x≡1(mod4)x \equiv 1 \pmod 4 and x≡2(mod6)x \equiv 2 \pmod 6 has NO solution: the first says xx is odd, the second that xx is even. When moduli are not coprime, the system is solvable only if the congruences agree modulo the gcd, and then the answer is unique only modulo the lcm.

Try it
Try it: remainder 1, then a multiple of 7

Find the least positive integer that leaves remainder 11 when divided by each of 2,3,4,5,62, 3, 4, 5, 6 and is divisible by 77.

Show the answer

Remainder 11 on division by 2,3,4,5,62, 3, 4, 5, 6 means N−1N - 1 is a multiple of lcm⁡(2,3,4,5,6)=60\operatorname{lcm}(2, 3, 4, 5, 6) = 60, so N=61,121,181,241,301,…N = 61, 121, 181, 241, 301, \dots. The first multiple of 77 is 301=7⋅43301 = 7 \cdot 43.

Orders and Totients

Tip
Euler's theorem and totient

If gcd⁡(a,n)=1\gcd(a,n)=1, then aφ(n)≡1(modn)a^{\varphi(n)}\equiv 1\pmod n, where φ(n)=n∏p∣n(1−1p)\varphi(n) = n\prod_{p\mid n}(1-\tfrac1p).

In plain terms. Like Fermat but for any modulus: raising to the "totient power" resets to 11. The totient counts how many numbers below nn share no factor with it.

Example. φ(10)=10(1−12)(1−15)=4\varphi(10) = 10(1-\tfrac12)(1-\tfrac15) = 4, so 34=81≡1(mod10)3^4 = 81\equiv 1\pmod{10}.

Why it works. List the φ(n)\varphi(n) numbers below nn that are coprime to nn and multiply each by aa. The products are still coprime to nn and are all different mod nn (if ax≡ayax \equiv ay then x≡yx \equiv y, because aa is invertible), so they are the same list in a new order. The two lists have the same product, so aφ(n)⋅(product)≡producta^{\varphi(n)} \cdot (\text{product}) \equiv \text{product}, and cancelling the product (which is invertible) leaves aφ(n)≡1a^{\varphi(n)} \equiv 1.

Concept
Order of an element

The order of aa mod nn is the least d>0d>0 with ad≡1a^d\equiv 1, and it always divides φ(n)\varphi(n).

In plain terms. It is the length of the repeating cycle of powers of aa — and that length must divide the totient, which narrows the possibilities.

Example. Order of 22 mod 77: 2,4,1,…2,4,1,\dots, so the order is 33, which divides φ(7)=6\varphi(7)=6.

Why the order divides φ(n)\varphi(n). Let dd be the order. Divide: φ(n)=qd+r\varphi(n) = qd + r with 0≤r<d0 \le r < d. Then 1≡aφ(n)=(ad)qar≡ar1 \equiv a^{\varphi(n)} = (a^d)^q a^r \equiv a^r, and r<dr < d forces r=0r = 0 by the minimality of dd. The same argument shows ak≡1a^k \equiv 1 exactly when d∣kd \mid k, which is what makes towers of exponents manageable.

Example
Worked: a tower of exponents

Find the remainder when 2220262^{2^{2026}} is divided by 77.

Spotting it. The base 22 has order 33 mod 77 (23=8≡12^3 = 8 \equiv 1), so only the exponent mod 33 matters. The exponent is itself a power of 22, and 2≡−1(mod3)2 \equiv -1 \pmod 3.

Step 1. 22026≡(−1)2026=1(mod3)2^{2026} \equiv (-1)^{2026} = 1 \pmod 3.

Step 2. So 222026≡21=2(mod7)2^{2^{2026}} \equiv 2^1 = 2 \pmod 7.

Example
Worked: the length of a repeating decimal

How many digits are in the repeating block of the decimal for 141\dfrac{1}{41}? And for 1287\dfrac{1}{287}?

Spotting it. For nn coprime to 1010, the decimal of 1n\tfrac1n repeats with period equal to the ORDER of 1010 mod nn: the remainders of long division are the powers of 1010 mod nn.

Step 1. The order of 1010 mod 4141 divides φ(41)=40\varphi(41) = 40. Test small divisors: 102=100≡1810^2 = 100 \equiv 18, 104≡182=324≡3710^4 \equiv 18^2 = 324 \equiv 37, 105≡370≡110^5 \equiv 370 \equiv 1. So the period is 55 (indeed 1/41=0.02439‾1/41 = 0.\overline{02439}).

Step 2. 287=7⋅41287 = 7 \cdot 41. The order of 1010 mod 77 is 66 (1/7=0.142857‾1/7 = 0.\overline{142857}). A power of 1010 is 11 mod 287287 exactly when it is 11 mod 77 and mod 4141, i.e. when the exponent is a multiple of both 66 and 55. The period is lcm⁡(6,5)=30\operatorname{lcm}(6, 5) = 30.

Side note
Where it goes wrong

Using φ(n)\varphi(n) as if it were the period. 1040≡1(mod41)10^{40} \equiv 1 \pmod{41} is true, but the repeating block of 141\tfrac1{41} has 55 digits, not 4040: Euler gives a multiple of the order, not the order itself. When the question is about the LEAST exponent, test the divisors of φ(n)\varphi(n).

Try it
Try it: another tower

Find the remainder when 331003^{3^{100}} is divided by 77.

Show the answer

The order of 33 mod 77 is 66 (36≡13^6 \equiv 1 and no smaller power works: 3,2,6,4,5,13, 2, 6, 4, 5, 1). So reduce the exponent mod 66: 31003^{100} is odd and divisible by 33, so 3100≡3(mod6)3^{100} \equiv 3 \pmod 6. Then 33100≡33=27≡6(mod7)3^{3^{100}} \equiv 3^3 = 27 \equiv 6 \pmod 7.

Valuations, Divisor Sums and Digits

Tip
Legendre's formula and trailing zeros
5101520253035404550row 1: multiples of 5 (10); row 2: multiples of 25 (2)
Counting the fives in 50!50! by rows: ⌊50/5⌋+⌊50/25⌋=10+2=12\lfloor 50/5 \rfloor + \lfloor 50/25 \rfloor = 10 + 2 = 12.

vp(n!)=⌊np⌋+⌊np2⌋+⋯v_p(n!) = \left\lfloor\tfrac np\right\rfloor + \left\lfloor\tfrac n{p^2}\right\rfloor + \cdots; trailing zeros of n!n! count v5(n!)v_5(n!).

Why it works. Count the factors of pp in 1⋅2⋯n1 \cdot 2 \cdots n by rows instead of by numbers: every multiple of pp contributes one, every multiple of p2p^2 one more, and so on. Row kk has ⌊n/pk⌋\lfloor n/p^k\rfloor entries.

100!100! ends in ⌊1005⌋+⌊10025⌋=20+4=24\left\lfloor\tfrac{100}5\right\rfloor + \left\lfloor\tfrac{100}{25}\right\rfloor = 20 + 4 = 24 zeros, because fives are scarcer than twos. AIME versions ask for the power of a prime in a binomial coefficient, where Kummer's theorem — the exponent equals the number of carries when adding in base pp — turns the computation into base-pp addition.

Tip
Divisor sums are multiplicative

d(n)=∏(ai+1)d(n) = \prod(a_i+1), σ(n)=∏piai+1−1pi−1\sigma(n) = \prod\dfrac{p_i^{a_i+1}-1}{p_i-1}, and both are multiplicative across coprime factors.

So σ(72)=σ(8)σ(9)=15⋅13=195\sigma(72) = \sigma(8)\sigma(9) = 15\cdot13 = 195 and d(72)=4⋅3=12d(72) = 4\cdot3 = 12. Problems asking for "the number of divisors of nn that are perfect squares" restrict each exponent to even values, giving ∏(⌊ai2⌋+1)\prod\left(\left\lfloor\tfrac{a_i}2\right\rfloor + 1\right) — the same product with a floor, and that pattern answers most divisor-counting variants.

Example
Worked: an AIME-style digit count

How many zeros does 200!200! end in?

Step 1 — zeros come from factors of 10=2⋅510 = 2\cdot5, and twos are plentiful, so count fives.

Step 2 — v5(200!)=⌊2005⌋+⌊20025⌋+⌊200125⌋=40+8+1=49v_5(200!) = \left\lfloor\tfrac{200}5\right\rfloor + \left\lfloor\tfrac{200}{25}\right\rfloor + \left\lfloor\tfrac{200}{125}\right\rfloor = 40 + 8 + 1 = 49.

Step 3 — so 200!200! ends in 4949 zeros.

Example
Worked: a prime in a binomial coefficient

Find the largest nn such that 3n3^n divides (10050)\dbinom{100}{50}.

Spotting it. (10050)=100!50! 50!\dbinom{100}{50} = \dfrac{100!}{50!\,50!}, so its 33-adic valuation is v3(100!)−2v3(50!)v_3(100!) - 2v_3(50!), and Legendre computes each piece.

Step 1. v3(100!)=33+11+3+1=48v_3(100!) = 33 + 11 + 3 + 1 = 48.

Step 2. v3(50!)=16+5+1=22v_3(50!) = 16 + 5 + 1 = 22.

Step 3. 48−44=448 - 44 = 4, so n=4n = 4.

Check with Kummer: 50=1212350 = 1212_3, and adding 12123+121231212_3 + 1212_3 produces a carry in each of the four places, so the valuation is 44 ✓

Example
Worked: the odd divisors

Find the sum of the odd positive divisors of 360360.

Spotting it. An odd divisor uses no factor of 22, so the odd divisors of 360=23⋅32⋅5360 = 2^3 \cdot 3^2 \cdot 5 are exactly the divisors of 45=32⋅545 = 3^2 \cdot 5.

Step 1. σ(45)=σ(9)σ(5)=(1+3+9)(1+5)=13⋅6=78\sigma(45) = \sigma(9)\sigma(5) = (1 + 3 + 9)(1 + 5) = 13 \cdot 6 = 78.

Side note
Where it goes wrong

Stopping Legendre's sum too early. For 200!200!, ⌊2005⌋+⌊20025⌋=48\lfloor\tfrac{200}{5}\rfloor + \lfloor\tfrac{200}{25}\rfloor = 48 misses the multiple of 125125, which carries a THIRD factor of 55; the true count is 4949. Keep dividing until the power of pp exceeds nn.

Try it
Try it: count the divisors that are squares

How many divisors of 720720 are perfect squares?

Show the answer

720=24⋅32⋅5720 = 2^4\cdot3^2\cdot5. Even exponents: 33 choices for the 22s (0,2,40,2,4), 22 for the 33s (0,20,2), 11 for the 55 — 66 square divisors.