Created
May 14, 2011 05:57
-
-
Save gnp/971963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The sum of the squares of the first ten natural numbers is, | |
1^2 + 2^2 + ... + 10^2 = 385 | |
The square of the sum of the first ten natural numbers is, | |
(1 + 2 + ... + 10)^2 = 55^2 = 3025 | |
Hence 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. | |
---------- | |
sum of squares: | |
$ perl -e '$a = 0; foreach $i (1..100) { $a += $i * $i } print "$a\n"' | |
338350 | |
square of sum: | |
SUM(1...n) = n(n + 1) / 2 | |
SUM(1...100) = 100 * 101 / 2 = 10100 / 2 = 5050 | |
squaring that: = 5050 * 5050 = 25502500 | |
difference = 25502500 - 338350 = 25164150 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment