[Tutor] Project Euler Problem 6

kinuthia muchane muchanek at gmail.com
Thu Apr 24 22:13:31 CEST 2008


Hi,

I am trying to solve problem 6 on the Project Euler, but when I submit
my answer, I am told that it is wrong. Here is the problem:


The sum of the squares of the first ten natural numbers is,


                       1² + 2² + ... + 10² = 385
The square of the sum of the first ten natural numbers is,


                    (1 + 2 + ... + 10)² = 55² = 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.

And here is my code:

def aux():
	return sum([k*k for k in range(1,111)])# sum of the squares of the
first one hundred numbers
	
def aux1():
	inter = sum([k for k in range(1,111))# square of the sum of the first
one hundred numbers
	return inter**2

def aux2():
 return aux1() - aux()# the difference of the two sums

print aux2()

...which gives a result of 36821290.

It worked fine with the example they have given but not with the hundred
one... What am I missing?

Thanks!
Kinuthia...






More information about the Tutor mailing list