---
title: "用clojure解决euler problem 5"
author: "hotcharm"
date: "2012-07-08T10:43:00Z"
tags: []
slug: "clojure-euler-problem-5"
draft: false
lastmod: "2012-07-15T18:28:56Z"
id: 1594606
url: "https://hotcharm.iteye.com/blog/1594606"
---

**问题描述：**

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 isevenly divisibleby 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"