r₂(n): how many ways to write n as a sum of two squares

each cell is n = 1..3000, left to right, top to bottom. colour = number of integer pairs (a,b) with a²+b²=n, counting order and sign. hover for n and its count.

 

the closed form is r₂(n) = 4·(d₁(n) − d₃(n)), where d₁ counts divisors ≡1 mod 4 and d₃ counts divisors ≡3 mod 4. verified against brute force for every n from 1 to 3000: zero mismatches.

so r₂ is always a multiple of 4, and never 4k+2. it is 0 for a bit over two thirds of n — exactly the n with any prime ≡3 mod 4 to an odd power. the biggest here is 32 (n=1105 and 1625 and 1885...), and a number can have arbitrarily many representations.