Project Euler Problem6

2015. 2. 5. 18:15프로그래밍/알고리즘

728x90
728x90

Problem6.

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.


나의 풀이)

제곱수 차이 구하는 건데 아주 쉬웠다.

그냥 코드로 짜려면 100이기 때문에 for문으로 돌리면 계산량이 장난이 아니겠지만..

이건 그냥 수학!

오랜만에 펜 잡고 몇 자 적었다.


이렇게 식 구해서 n에 값만 넣으면 답이 나온다.

코드는 겨우 4줄.




728x90
반응형

'프로그래밍 > 알고리즘' 카테고리의 다른 글

Project Euler Problem16  (0) 2015.02.24
Project Euler Problem15  (0) 2015.02.17
Project Euler Problem10  (0) 2015.02.15
Project Euler Problem9  (0) 2015.02.15
Project Euler Problem5  (0) 2015.02.12
Project Euler Problem7  (0) 2015.02.05
Project Euler Problem4  (0) 2015.01.25