[문제 링크]
http://projecteuler.net/problem=6
[문제 원본]
The sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
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.
[문제 설명]
1~100까지 합의 제곱 에서 1의 제곱 더하기 2의 제곱 더하기 … 100의 제곱을 더한값을 뺀 값을 구하라.
[소스 코드]
import time sTime = time.clock() sqrAndSum = 0 sumAndSqr = 0 for i in range(1, 101): sqrAndSum = sqrAndSum + (i*i) sumAndSqr = 0 for i in range(1, 101): sumAndSqr = sumAndSqr + i sumAndSqr = (sumAndSqr * sumAndSqr) print("Result=", sumAndSqr - sqrAndSum, "time=", (time.clock() - sTime) * 100)
[출력 결과]
(‘Result=’, 25164150, ‘time=’, 0.007399999999999768)