Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3c80364

Browse files
SandersLinpoyea
authored andcommitted
Project Euler problem 6 solution 3 (TheAlgorithms#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

Lines changed: 20 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /