Project Euler - Problem6 └ Project Euler

Problem 6

14 December 2001

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.


문제 6.
(1 + 2 + ... + 1000)
2  -   ( 12 + 22 + ... + 10002 )  = ?

erlang code.
-module( problem6 ).
-export( [calc/1] ).

calc(N) ->
        SumOfSqr = lists:sum( [ math:pow(X, 2) || X <- lists:seq( 1, N ) ] ),
        SqrOfSum = math:pow( lists:sum( lists:seq( 1, N ) ), 2 ),
        (SqrOfSum - SumOfSqr).



정말 간단한..  문제.

덧글

댓글 입력 영역


통계 위젯 (블랙)

01
9
53794

이 이글루를 링크한 사람 (블랙)

11