File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ Problem:
3
+ The sum of the squares of the first ten natural numbers is,
4
+ 1^2 + 2^2 + ... + 10^2 = 385
5
+ The square of the sum of the first ten natural numbers is,
6
+ (1 + 2 + ... + 10)^2 = 552 = 3025
7
+ 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.
8
+ Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
9
+ '''
10
+ from __future__ import print_function
11
+ import math
12
+ def problem6 (number = 100 ):
13
+ sum_of_squares = sum ([i * i for i in range (1 ,number + 1 )])
14
+ square_of_sum = int (math .pow (sum (range (1 ,number + 1 )),2 ))
15
+ return square_of_sum - sum_of_squares
16
+ def main ():
17
+ print (problem6 ())
18
+
19
+ if __name__ == '__main__' :
20
+ main ()
You can’t perform that action at this time.
0 commit comments