#Problem 5. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
번역: 1부터 20까지 수로 모두 나누어 떨어지는 수 중 가장 작은 수는?
뭐 복잡하게 설명할 것 없이
최소공배수(LCM, Lowest Common Multiple)를 구하는 문제다.
Result = (lcm ...... (lcm (lcm 1 2) 3) 4) ... 20)
let lcm x y =
let rec gcd x y =
match y with
| 0 -> x
| _ -> (gcd y (x%y))
x * (y / (gcd x y))
{1 .. 20}
|> Seq.fold lcm 1
|> printfn "Problem #5 = %d"
조금 어려운 문제로 번호를 넘겨야 할 듯...
'내 생산물' 카테고리의 다른 글
| F#, Project Euler - Problem #4 (2) (0) | 2009/05/22 |
|---|---|
| F#, Project Euler - Problem #12 (0) | 2009/05/12 |
| F#, Project Euler - Problem #20 (0) | 2009/05/12 |
| F#, Project Euler - Problem #5 (0) | 2009/05/11 |
| F#, Project Euler - Problem #4 (2) | 2009/05/11 |
| F#, Project Euler - Problem #3 (0) | 2009/05/10 |
| F#, Project Euler - Problem #1 (2) | 2009/05/10 |
