#C5932. Sum of Squares of Natural Numbers
Sum of Squares of Natural Numbers
Sum of Squares of Natural Numbers
You are given a single positive integer n
. Your task is to compute the sum of the squares of the first n
natural numbers.
The result is given by the mathematical formula:
$$\frac{n(n+1)(2n+1)}{6}$$
For example, if n = 3
, the answer is 1^2 + 2^2 + 3^2 = 14
.
inputFormat
The input consists of a single integer n
(1 ≤ n ≤ 109 for theoretical cases, however the test cases provided are of moderate size).
The input should be read from standard input (stdin).
outputFormat
Output a single integer which is the sum of the squares of the first n
natural numbers.
The output should be written to standard output (stdout).
## sample1
1