Project Euler その2

Problem3,4がなんかめんどくさそうだったので一旦飛ばす。

Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is divisible by all of the numbers from 1 to 20?

2520は1から10までの数で余りを出さずに割れる最小の数である。1から20の数すべてで公平に割れる最小の数字は何か?

コード
print 2520*11*13*2*17*19

2520=2*2*2*3*3*5*7 であり、11~20に含まれる素数以外の数は

12=2*2*3
14=2*7
15=3*5
16=2*2*2*2
18=2*9
20=2*2*5 となるので、2520の素因数で足りないのは2が1つだけ。よって求めたい値は

2520*11*13*2*17*19 となる。

Problem 6

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

1^2 + 2^2 + ... + 10^2 = 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.

10までの自然数の2乗の和は、
1^2 + 2^2 + ... + 10^2 = 385 となる。
10までの自然数の和の2乗は、
(1 + 2 + ... + 10)^2 = 552 = 3025 となる。

従って、自然数の最初の10個の2乗と和の2乗の差は、
3025 - 385 = 2640 となる。
100までの自然数の和の2乗と2乗の和の差を求めよ。

コード
a=5050**2

s=0
for i in range(1,101):
    s += i**2

print a-s

1~100の総和は5050なので和の2乗は5050^2で求められる。