The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 3025Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
the square of the sum.A straight forward problem.
1) Brute-force like all the days:
Can't argue brute-force is the best way to deal with such a small limit as 100. Just loop though 1 to 100 and sum up the sum of the squares and the square of the sum in two vars, return the difference.
2) Smarter Parametrization:
As this is a problem about 2 series, there must be some mathematical parametrization can be done.
Just by litter research, some summation formulas can be found efortlessly
[GitHub Link] [Official overview pdf by projecteuler.net]
1) Brute-force like all the days:
Can't argue brute-force is the best way to deal with such a small limit as 100. Just loop though 1 to 100 and sum up the sum of the squares and the square of the sum in two vars, return the difference.
2) Smarter Parametrization:
As this is a problem about 2 series, there must be some mathematical parametrization can be done.
Just by litter research, some summation formulas can be found efortlessly
[GitHub Link] [Official overview pdf by projecteuler.net]