Back to Math Tools

Sum of Five Squares

Calculate r₅(n) - the number of ways to represent n as a sum of five squares.

Enter a Number (n)

Enter n (0 to 1000) to calculate r₅(n)

How It Works

r₅(n) counts the number of ways to write n as x₁² + x₂² + x₃² + x₄² + x₅² where the xᵢ are integers (positive, negative, or zero) and order matters.

The Four-to-Five Bridge: r₅(n) = Σⱼ r₄(n - j²), where j ranges over all integers with j² ≤ n. This lets us compute r₅ using the simpler r₄ function.

Jacobi's Four-Square Theorem: r₄(n) = 8 × (sum of divisors of n that are not divisible by 4). This gives us an exact formula for four squares.

Grosswald's Asymptotic Formula: For large n, r₅(n) grows proportionally to n^(3/2).

Universality: Every integer n > 33 can be expressed as a sum of five nonzero squares.

Frequently Asked Questions

Can every positive integer be written as a sum of five squares?

Yes, every positive integer can be expressed as a sum of five squares (allowing zeros). Moreover, every integer greater than 33 can be written as a sum of five nonzero squares. This is stronger than the four-square theorem, which requires some zeros for numbers like 1, 2, 3, 5, 6, etc.

How is r5(n) computed?

The calculator uses a bridge formula: r5(n) = sum of r4(n-j^2) for all integers j with j^2 <= n. Here r4(m) uses Jacobi's formula: r4(m) = 8 times the sum of divisors of m not divisible by 4. This avoids slow enumeration and gives exact counts efficiently.

Why does r5(n) count ordered representations with signs?

r5(n) counts all ways including different orderings (1^2+0^2+0^2+0^2+0^2 vs 0^2+1^2+0^2+0^2+0^2) and different signs (1^2 vs (-1)^2). This is the standard definition in number theory, connecting to theta functions and modular forms. For distinct unordered representations, you'd divide by permutation and sign factors.

How fast does r5(n) grow?

Grosswald's asymptotic formula shows r5(n) grows proportionally to n^(3/2). More precisely, r5(n) ~ (pi^(5/2) / Gamma(5/2)) * n^(3/2) = (4/3)*pi^2 * n^(3/2). For n=1000, there are over 3 million representations, demonstrating this rapid growth.