I am doing Project Euler problem #6. This is the question it asks:
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 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.
The sum of the squares of the first ten natural numbers is,
$1ドル^2 + 2^2 + \ldots + 10^2 = 385$$
The square of the sum of the first ten natural numbers is,
$$(1 + 2 + \ldots + 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.
My implementation in pythonPython is as follows:
def sum_of_squares(n):
return sum([i**2 for i in range(1, n+1)])
def square_of_sum(n):
return sum(range(1, n+1)) ** 2
print square_of_sum(100) - sum_of_squares(100)
It works but I was wondering if my implementation is good and fast enough?
I am doing Project Euler problem #6. This is the question it asks:
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 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.
My implementation in python is as follows:
def sum_of_squares(n):
return sum([i**2 for i in range(1, n+1)])
def square_of_sum(n):
return sum(range(1, n+1)) ** 2
print square_of_sum(100) - sum_of_squares(100)
It works but I was wondering if my implementation is good and fast enough?
I am doing Project Euler problem #6. This is the question it asks:
The sum of the squares of the first ten natural numbers is,
$1ドル^2 + 2^2 + \ldots + 10^2 = 385$$
The square of the sum of the first ten natural numbers is,
$$(1 + 2 + \ldots + 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.
My implementation in Python is as follows:
def sum_of_squares(n):
return sum([i**2 for i in range(1, n+1)])
def square_of_sum(n):
return sum(range(1, n+1)) ** 2
print square_of_sum(100) - sum_of_squares(100)
It works but I was wondering if my implementation is good and fast enough?
Sum of Squares/Square of Sum Difference
I am doing Project Euler problem #6. This is the question it asks:
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 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.
My implementation in python is as follows:
def sum_of_squares(n):
return sum([i**2 for i in range(1, n+1)])
def square_of_sum(n):
return sum(range(1, n+1)) ** 2
print square_of_sum(100) - sum_of_squares(100)
It works but I was wondering if my implementation is good and fast enough?