Skip to content

Commit 3c80364

Browse files
SandersLinpoyea
authored andcommitted
Project Euler problem 6 solution 3 (#640)
1 parent 9417091 commit 3c80364

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

project_euler/problem_06/sol3.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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()

0 commit comments

Comments
 (0)