Maths & numbers

Sum of two squares calculator for integer representations

List every unordered nonnegative integer pair whose squares sum to n, with a separate signed/ordered representation count and prime-factor existence check.

Your numbers

Enter a base-ten integer without commas, decimals or scientific notation.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

This page searches for integer representations, so arbitrary decimal square-root pairs are not included. It lists each nonnegative unordered pair once with a≤b, then separately counts the signed and ordered lattice points represented by that pair. Exact integer square-root and monotone scanning routines avoid relying on rounded floating square tests. A prime-factor formula independently checks the total signed/ordered count and identifies an obstruction when no representation exists.

THE FORMULAa²+b²=n with 0≤a≤b; for n>0, r₂(n)=4∏(e_p+1) over p≡1 mod4 if all p≡3 mod4 exponents are even, otherwise zero.

A worked example

For n=25, the nonnegative unordered pairs are (0,5) and (3,4). The axis pair gives four signed/ordered points: (0,±5) and (±5,0). The unequal positive pair gives eight from its two orders and four sign choices. The table therefore has two rows, while r₂(25)=12. Since 25=5² and 5≡1 modulo four, the independent formula also gives 4*(2+1)=12.

Good to know

Nonnegative integers through 10¹⁰. Zero coordinates are allowed, exchanged legs are merged in the pair table and sign changes are counted separately. The special input n=0 returns the pair (0,0) and count one. Inputs are not required to produce coprime coordinates. The prime-factor criterion addresses existence as two integer squares, not representation by positive squares only or by a prescribed pair of magnitudes.

One pair can represent four or eight lattice points

When both coordinates are positive and unequal, exchanging them gives a different ordered pair and each coordinate has two sign choices, for eight points. If the coordinates are equal, exchange creates no new pair, leaving four sign choices. If one coordinate is zero, its sign creates no new value, and the axis locations again total four. Applying a blanket factor of eight to every row would overcount both of these boundary cases.

For n=50, the pairs (1,7) and (5,5) contribute eight and four, giving twelve signed/ordered representations. For n=1 only the axis pair (0,1) exists. For zero, all sign and order choices collapse to the same point, and r₂(0)=1. These examples show why the pair count, geometric lattice-point count and a positive-coordinate-only count should be kept distinct instead of reported under one ambiguous total.

Two unordered pairs account for twelve signed ordered lattice points on a radius-five circle(0,5) → 4(3,4) → 8Total: 12
For n=25, the nonnegative pairs are (0,5) and (3,4). Their axis and nonaxis sign/order variants contribute four and eight points respectively, giving r₂(25)=12. All twelve points are drawn on the same circle.

The Primitive Pythagorean triples calculator with a hypotenuse limit requires a sum of two positive squares to equal a square and applies a separate primitive-seed convention.

An odd exponent on a prime congruent to three modulo four blocks every pair

For positive n, a prime factor congruent to three modulo four must appear to an even exponent in any sum of two integer squares. Thus n=3 has no pair, while n=9 has (0,3): its exponent of three is two. The condition is about exponents in the complete factorization, not whether n itself happens to be one or three modulo four. Numbers divisible by several such primes still require every one of their exponents to be even.

The implementation enumerates the pairs and compares their signed/ordered contribution with the factor-count formula. Those independent views check different errors: a scan can miss or duplicate a lattice point, while a counting convention can mishandle an axis or diagonal pair. A representation also need not be primitive. For n=100, (0,10) and (6,8) have nontrivial coordinate GCDs but remain valid rows. A coprimality filter would solve another question and is not imposed here.

A few questions, answered

Can I require both coordinates to be positive?

The table includes zero coordinates by design. For the positive-only subset, disregard axis rows and keep the remaining rows; the displayed signed/ordered total still follows the documented convention including axes.

Does every nonnegative n have a representation?

No. The prime-factor obstruction rules out many integers. A decimal identity involving square roots is not an integer representation and is not included in the output.

Find your calculator

Start typing to explore the library.