Problem Archive

A number is a perfect square, or a square number, if it is the square of a positive integer. For example, $25$ is a square number because $5^2 = 5 \times 5 = 25$; it is also an odd square.

The first $5$ square numbers are: $1, 4, 9, 16, 25$, and the sum of the odd squares is $1 + 9 + 25 = 35$.

Among the first $945$ thousand square numbers, what is the sum of all the odd squares?

Solution

Sum of the Odd Squares Among the First 945,000 Square Numbers

The first 945,000 square numbers are:

1², 2², 3², 4², ..., 945000²

We only want the odd ones. An odd square comes from an odd base, so the squares we care about are:

1², 3², 5², 7², ..., 944999²

Step 1: Count how many odd squares there are

Odd numbers go 1, 3, 5, 7, .... Among the first 945,000 positive integers, exactly half are odd:

m = 945000 / 2 = 472500

So we are summing m = 472,500 odd squares — from the 1st odd base up to the 472,500th odd base.

The r-th odd number is (2r − 1), so the sum we want is:

S_m = 1² + 3² + 5² + ... + (2m − 1)²  =  Σ (2r − 1)²   for r = 1 to m

Step 2: Expand the square

(2r − 1)² = 4r² − 4r + 1

So:

S_m = 4·Σ r²  −  4·Σ r  +  Σ 1

Step 3: Use the two classic sum formulas

Plug them in:

S_m = 4·m(m+1)(2m+1)/6  −  4·m(m+1)/2  +  m

Step 4: Simplify

S_m = (2/3)·m(m+1)(2m+1)  −  2m(m+1)  +  m

Factor out m and simplify the bracket:

S_m = m·[ (2/3)(2m² + 3m + 1) − 2(m+1) + 1 ]

    = m·(4m² − 1)/3

And since 4m² − 1 = (2m − 1)(2m + 1):

S_m = m(2m − 1)(2m + 1) / 3

Step 5: Plug in m = 472,500

S = 472500 × (2×472500 − 1) × (2×472500 + 1) / 3

  = 472500 × 944999 × 945001 / 3

  = 157500 × 944999 × 945001

Using 944999 × 945001 = (945000 − 1)(945000 + 1) = 945000² − 1 = 893024999999:

S = 157500 × 893024999999

Final Answer

140,651,437,499,842,500

Sanity check with a tiny case

The problem statement itself says the sum of the first 3 odd squares is 35. Our formula with m = 3:

3 × (2×3 − 1) × (2×3 + 1) / 3 = 3 × 5 × 7 / 3 = 35

✓ Matches.

Quick Python verification:

m = 472_500
print(m * (2*m - 1) * (2*m + 1) // 3)
**140651437499842500**
Problems sourced from Project Euler · Non-commercial & educational use only · CC BY-NC-SA 4.0