In modular arithmetic, Thue's lemma roughly states that every modular integer may be represented by a "modular fraction" such that the numerator and the denominator have absolute values not greater than the square root of the modulus.
More precisely, for every pair of integers (a, m) with m > 1, given two positive integers X and Y such that X ≤ m < XY, there are two integers x and y such that
and
Usually, one takes X and Y equal to the smallest integer greater than the square root of m, but the general form is sometimes useful, and makes the uniqueness theorem (below) easier to state.[1]
The first known proof is attributed to Axel Thue (1902)[2] who used a pigeonhole argument.[3] It can be used to prove Fermat's theorem on sums of two squares by taking m to be a prime p that is congruent to 1 modulo 4 and taking a to satisfy a2 + 1 ≡ 0 mod p. (Such an "a" is guaranteed for "p" by Wilson's theorem.[4])