問題描述:
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?
即求1到20的所有數的最小公倍數。
解決方案:
(ns euler-problem-5.core
(:use clojure.contrib.math))
(defn smallest-lcm-from-1-to
[num]
(loop
[current-num 1 result 1]
(if (= current-num num)
(lcm result num)
(recur (inc current-num) (lcm current-num result)))))
(smallest-lcm-from-1-to 20)
運行結果:232792560
"Elapsed time: 0.301993 msecs"