On this page
A lattice point is a point whose coordinates are both integers. Ask how many of them sit on the circle x² + y² = 25 and it is easy to find (3, 4) and stop. The true answer is 12, and a formula gives it without any searching.
What is r₂(n), the number of lattice points on a circle?
Mathematicians write r₂(n) for the number of integer pairs (x, y) with x² + y² = n, where different signs and different orders count as different pairs (sum of squares function). That is exactly the number of lattice points on the circle of radius √n centred at the origin, as the OEIS entry A004018 describes it.
Jacobi's two-square theorem gives the count: r₂(n) = 4(d₁(n) − d₃(n)), where d₁(n) counts the divisors of n that are 1 more than a multiple of 4 and d₃(n) counts those that are 3 more (sum of two squares theorem). The factor 4 comes from symmetry: turning a lattice point through 90° about the origin gives another.
Why do primes of the form 4k + 1 and 4k + 3 decide the count?
Every square leaves remainder 0 or 1 when divided by 4, so a sum of two squares leaves 0, 1 or 2, never 3. That is why 3, 7, 11 and 19 are not sums of two squares. Fermat's theorem on sums of two squares says the reverse holds for primes: an odd prime p can be written as x² + y² exactly when p leaves remainder 1 on division by 4, as in 5 = 1² + 2² and 13 = 2² + 3².
The sum of squares function article turns this into a recipe. Write n = 2^g × p₁^f₁ × p₂^f₂ × ⋯ × q₁^h₁ × ⋯, with each p of the form 4k + 1 and each q of the form 4k + 3. Then:
If any exponent h on a 4k + 3 prime is odd, r₂(n) = 0.
Otherwise r₂(n) = 4(f₁ + 1)(f₂ + 1)⋯.
The power of 2, and even powers of 4k + 3 primes, do not change the count.
The recipe leans on unique prime factorisation, which is one reason 1 is not counted as a prime number.
How many lattice points are on x² + y² = 25, 65 and 325?
Each count uses the product formula from the sum of squares function article, checked by divisors and by listing points.
For n = 25: 25 = 5², and 5 = 4 × 1 + 1. One prime of the form 4k + 1 with exponent 2, so r₂(25) = 4 × (2 + 1) = 12. Divisor check: 1, 5 and 25 all leave remainder 1, so 4 × (3 − 0) = 12. The points are (±5, 0), (0, ±5), (±3, ±4) and (±4, ±3).
For n = 65: 65 = 5 × 13, and both primes are of the form 4k + 1. So r₂(65) = 4 × 2 × 2 = 16. The two basic ways are 65 = 1² + 8² = 4² + 7², and each gives 8 points once you allow signs and swaps: (±1, ±8), (±8, ±1), (±4, ±7) and (±7, ±4).
Those two ways come from the Brahmagupta–Fibonacci identity: (a² + b²)(c² + d²) = (ac ± bd)² + (ad ∓ bc)². From 5 = 1² + 2² and 13 = 2² + 3², one choice of signs gives 8² + 1², the other 4² + 7².
For n = 325: 325 = 5² × 13, so r₂(325) = 4 × 3 × 2 = 24. The three basic ways are 1² + 18², 6² + 17² and 10² + 15², each worth 8 points.
What mistakes cost marks when counting lattice points?
Counting (3, 4) as one point. Signs and order turn one way of writing n into as many as 8 points.
Missing the axis points. 25 = 5² + 0² adds (±5, 0) and (0, ±5), which give 4 points, not 8.
Giving up at the first 4k + 3 prime. 21 = 3 × 7 gives 0 points, but 9 = 3² gives 4: (±3, 0) and (0, ±3). Only an odd exponent kills the count.
How do you count lattice points on a circle in a test?
Factorise n completely.
Check each prime of the form 4k + 3. Any odd exponent means the answer is 0.
Multiply (exponent + 1) over the primes of the form 4k + 1, then multiply by 4.
Sanity-check: find one point by trying x up to √(n/2).
If you get a different answer from the book, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer. If remainders mod 4 still feel shaky, the Fermi Concept Library gives each concept in mathematics its own lesson.
For the same dot-grid thinking applied to area, read Pick's theorem for polygons on a dot grid.


