Olympiad Number Theory II: Residues, Diophantine Equations & Factorials

Study Sheet

Olympiad Number Theory II: Residues, Diophantine Equations & Factorials

Quadratic residues, difference-of-squares counts, Legendre gaps, Euler at work

Deeper Arithmetic

Tip
Quadratic residues and the two supplements

For an odd prime pp: 1-1 is a QR iff p1(mod4)p \equiv 1 \pmod 4; 22 is a QR iff p±1(mod8)p \equiv \pm1 \pmod 8. Euler's criterion: a(p1)/2(ap)a^{(p-1)/2} \equiv \left(\tfrac ap\right).

Eleven odd primes up to 100100 have 1-1 as a residue — exactly the primes that are sums of two squares (Fermat). Quadratic reciprocity (pq)(qp)=(1)p12q12\left(\tfrac pq\right)\left(\tfrac qp\right) = (-1)^{\frac{p-1}{2}\frac{q-1}{2}} then decides every (ap)\left(\tfrac ap\right) by a Euclid-like descent. Olympiad use: showing an equation like x2+10(modp)x^2 + 1 \equiv 0 \pmod p has no solution for p3(mod4)p \equiv 3 \pmod 4 kills whole families of Diophantine equations mod a well-chosen prime.

Tip
Difference of squares and factorization counts

x2y2=Nx^2 - y^2 = N has positive solutions in bijection with factorizations N=deN = de, d<ed < e, de(mod2)d \equiv e \pmod 2. For odd NN the count is τ(N)12\tfrac{\tau(N) - 1}{2} when NN is a square, τ(N)2\tfrac{\tau(N)}{2} otherwise.

x2y2=2025=3452x^2 - y^2 = 2025 = 3^4\cdot5^2: τ=15\tau = 15, so 77 solutions (the factorization 454545\cdot45 gives y=0y = 0 and is excluded). For even NN both factors must be even, so N2(mod4)N \equiv 2 \pmod 4 has NO solutions — the standard parity obstruction. Every "sum/difference of squares" count is a divisor count in disguise.

Tip
Factorials: gaps in trailing zeros and Euler's theorem

v5(n!)v_5(n!) jumps by 22 at multiples of 2525 and by 33 at multiples of 125125, so some zero-counts (5,11,17,,29,305, 11, 17, \ldots, 29, 30) never occur. Euler: aφ(n)1a^{\varphi(n)} \equiv 1 when gcd(a,n)=1\gcd(a,n) = 121001(mod125)2^{100} \equiv 1 \pmod{125}.

The smallest nn with at least 3030 trailing zeros is 125125 (v5v_5 leaps from 2828 at 124124 to 3131). Euler plus CRT computes huge powers modulo composites: 21001(mod125)2^{100} \equiv 1 \pmod{125} and 0(mod8)\equiv 0 \pmod 8 give 2100376(mod1000)2^{100} \equiv 376 \pmod{1000}. Wilson's theorem (p1)!1(p-1)! \equiv -1 handles factorials modulo primes; pairing each residue with its inverse is the proof.

Side note
The mod-mm obstruction menu

Squares are 0,1mod40, 1 \bmod 4 and 0,1,4mod80, 1, 4 \bmod 8; cubes are 0,±1mod90, \pm1 \bmod 9 and mod7\bmod 7; fourth powers are 0,1mod160, 1 \bmod 16. Powers of 22 cycle with short periods mod small odd numbers. Before any heavy machinery, reduce a Diophantine equation modulo 4,8,9,7,164, 8, 9, 7, 16 — one of them usually shows there are no solutions, or restricts them to a residue class you can then handle.

Try it
Try it: kill an equation mod 4

Show x2+y2=4z+3x^2 + y^2 = 4z + 3 has no integer solutions.

Squares are 00 or 1mod41 \bmod 4, so x2+y2{0,1,2}mod4x^2 + y^2 \in \{0, 1, 2\} \bmod 4 — never 33. Done in one line; the same idea shows no integer of the form 4k+34k + 3 is a sum of two squares.

Proofs & Why It Matters

Tip
Proof: Euler's criterion

For odd prime pp and pap \nmid a: a(p1)/21a^{(p-1)/2} \equiv 1 if aa is a QR, 1\equiv -1 otherwise.

The multiplicative group mod pp is cyclic of order p1p - 1 with generator gg; write a=gka = g^k. Then a(p1)/2=gk(p1)/2a^{(p-1)/2} = g^{k(p-1)/2}, which is 11 iff (p1)kp12(p - 1) \mid k\tfrac{p-1}{2} iff kk is even iff aa is a square (a=(gk/2)2a = (g^{k/2})^2). Since ap1=1a^{p-1} = 1, the value a(p1)/2a^{(p-1)/2} is a square root of 11, hence ±1\pm1. \blacksquare The first supplement follows immediately: (1)(p1)/2=1(-1)^{(p-1)/2} = 1 iff p12\tfrac{p-1}{2} is even iff p1(mod4)p \equiv 1 \pmod 4.

Tip
Proof: Wilson's theorem

(p1)!1(modp)(p - 1)! \equiv -1 \pmod p for every prime pp.

In the product 12(p1)1\cdot2\cdots(p-1), pair each residue with its multiplicative inverse mod pp. A residue is its own inverse iff x21x^2 \equiv 1 iff x±1x \equiv \pm1 (a polynomial of degree 22 over a field has at most 22 roots). All other residues pair off into products 1\equiv 1, leaving 1(p1)11\cdot(p-1) \equiv -1. \blacksquare Significance: the converse holds too (nn composite (n1)!0\Rightarrow (n-1)! \equiv 0 for n>4n > 4), so Wilson characterizes primes — and the pairing trick reappears in every "product of all elements of a group" problem.

Going Deeper: Worked Problems

Example
Worked: a two-squares count

How many ordered pairs of positive integers (x,y)(x, y) satisfy x2y2=720x^2 - y^2 = 720?

Step 1 — (xy)(x+y)=720(x - y)(x + y) = 720 with both factors of the SAME parity; since 720720 is even, both must be even.

Step 2 — write xy=2dx - y = 2d, x+y=2ex + y = 2e: de=180de = 180 with d<ed < e.

Step 3 — 180=22325180 = 2^2\cdot3^2\cdot5 has τ=18\tau = 18 divisors, so 99 pairs with d<ed < e (no square root since 180180 is not a square).

Step 4 — each gives x=d+ex = d + e, y=ed>0y = e - d > 0: nine solutions. The parity step is where most attempts go wrong — an odd-times-even factorization of 720720 gives non-integer x,yx, y.

Example
Worked: an order argument for a divisibility claim

Show that 2n+12^n + 1 is never divisible by 77 for any positive integer nn.

Step 1 — the powers of 22 mod 77 cycle: 2,4,1,2,4,1,2, 4, 1, 2, 4, 1, \ldots (the order of 22 mod 77 is 33).

Step 2 — so 2nmod7{1,2,4}2^n \bmod 7 \in \{1, 2, 4\} and 2n+1mod7{2,3,5}2^n + 1 \bmod 7 \in \{2, 3, 5\} — never 00. \blacksquare

Step 3 — the general principle: p2n+1p \mid 2^n + 1 requires 22n12^{2n} \equiv 1 but 2n≢12^n \not\equiv 1, i.e. the order of 22 mod pp is exactly 2(something dividing n)2\cdot(\text{something dividing } n) — an EVEN order. Mod 77 the order is 33, odd: impossible. This "order must be even" lemma settles every an+1a^n + 1 divisibility question.