Sum of Two Squares Calculator and Representation Finder

Check whether n = a² + b² and find every unique nonnegative pair. Exact factorization and enumeration run privately in your browser.

Enter a nonnegative integer

Commas, spaces, or underscores may group digits in sets of three. Negative values and decimals are not valid because this tool searches integer squares.

Representations and theorem check

Your result will appear here.

For n = 325, select Find representations to get (1, 18), (6, 17), and (10, 15), plus the prime-factor test.

Advertisement

Fermat’s sum of two squares theorem

For a positive integer n, first write its prime factorization. A representation n = a² + b² exists exactly when every prime factor that is 3 modulo 4 has an even exponent.

n = 2e₀ · ∏ pᵢeᵢ · ∏ qⱼfⱼ

pᵢ ≡ 1 (mod 4), qⱼ ≡ 3 (mod 4)

n = a² + b² ⇔ every fⱼ is even

The power of 2 and the exponents on primes that are 1 modulo 4 do not block existence. The calculator shows each factor’s residue class and whether it passes the condition.

Unique pairs versus ordered signed representations

The unique list

This calculator lists only pairs with 0 ≤ ab. That removes duplicates caused by swapping the two values or changing their signs.

For example, the unique pair (1, 2) represents the eight ordered signed pairs formed by choosing signs and swapping coordinates.

The classical count r₂(n)

r₂(n) = 4 ∏(eᵢ + 1)

The product uses only exponents of primes pᵢ ≡ 1 (mod 4), provided every 3-mod-4 exponent is even.

A pair with one zero or with a = b contributes four ordered signed pairs; a pair with 0 < a < b contributes eight.

Worked examples

65 has two unique representations

65 = 5 · 13

Both primes are 1 modulo 4, so the theorem permits representations. In fact, 65 = 1² + 8² = 4² + 7². Each pair contributes eight ordered signed solutions, giving r₂(65) = 16.

3 has no representation

3 = 3¹

The prime 3 is congruent to 3 modulo 4 and has odd exponent 1. It fails the theorem condition, so no integers a and b can satisfy a² + b² = 3.

25 includes a zero square

25 = 5² = 0² + 5² = 3² + 4²

The unique pairs are (0, 5) and (3, 4). Their symmetry contributions are four and eight, matching r₂(25) = 12.

45 passes despite a 3-mod-4 factor

45 = 3² · 5

The prime 3 occurs to the even exponent 2, so it does not block a representation. The unique pair is (3, 6), since 3² + 6² = 45.

Sum of two squares FAQ

When is an integer a sum of two squares?

A positive integer is a sum of two integer squares exactly when every prime congruent to 3 modulo 4 has an even exponent in its prime factorization. Zero is the special case 0² + 0².

Does order matter in the representation list?

No. The main list uses 0 ≤ ab, so (1, 8) and (8, 1) appear once as (1, 8). The ordered signed total counts both orders separately.

Can one of the squares be zero?

Yes. Every perfect square k² has the representation 0² + k². Zero itself has the single pair (0, 0).

How is the representation count calculated?

For positive n that passes the theorem, multiply 4 by e + 1 for every exponent e belonging to a prime factor congruent to 1 modulo 4. This gives all ordered signed pairs, including swaps and zero coordinates.

Why can a number have several different pairs?

Different lattice points can lie on the same circle x² + y² = n. For example, 65 has both (1, 8) and (4, 7).

What values can I enter?

Enter a whole number from 0 through 1,000,000,000,000. The upper limit keeps trial-division factorization and complete pair enumeration predictable on phones and desktop browsers.

Are my inputs private?

Yes. The calculation runs entirely in your browser and does not upload, save, or add your number to the page URL.

Explore more tools