ONLY DO WHAT ONLY YOU CAN DO

こけたら立ちなはれ 立ったら歩きなはれ

F# で Project Euler Problem 5

2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である.

では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか.

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 evenly divisible by all of the numbers from 1 to 20?

> let rec gcd  a b =
-     if b = 0L then a else gcd b a % b
- ;;

val gcd : int64 -> int64 -> int64

> let lcm a  b =
-     a * b / gcd a b
- ;;

val lcm : int64 -> int64 -> int64

> [1L..10L]
- |> List.reduce(lcm)
- ;;

Process is terminated due to StackOverflowException.
> let rec gcd  a b =
-     if b = 0L then a else gcd b (a % b)
- ;;

val gcd : int64 -> int64 -> int64

> let lcm a  b =
-     a * b / gcd a b
- ;;

val lcm : int64 -> int64 -> int64

> [1L..10L]
- |> List.reduce(lcm)
- ;;
val it : int64 = 2520L
> [1L..20L]
- |> List.reduce(lcm)
- ;;
val it : int64 = 232792560L
>