Sum of squares

Write a program that reads a natural number n, and prints the result of
the following sum:
1² + 2² + … + (n − 1)² + n².

Input

Input consists of a natural number n.

Output

Print the sum of the first n squares: $\sum_{i=1}^{n} i^2$.

Observation

The summation has a closed formula, so a loop would not be necessary to
solve this exercise.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:29:45.922Z

© Jutge.org, 2006–2026.
https://jutge.org
