Problem 5 » 履歴 » バージョン 3
Noppi, 2023/12/27 13:06
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 5]] |
||
3 | |||
4 | 3 | Noppi | ## Smallest Multiple |
5 | $2520$ is the smallest number that can be divided by each of the numbers from $1$ to $10$ without any remainder. |
||
6 | What is the smallest positive number that is **evenly divisible** (divisible with no remainder) by all of the numbers from $1$ to $20$? |
||
7 | |||
8 | ## 最小の倍数 |
||
9 | 2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である. |
||
10 | では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか. |
||
11 | |||
12 | 1 | Noppi | ```scheme |
13 | #!r6rs |
||
14 | #!chezscheme |
||
15 | |||
16 | (import (chezscheme)) |
||
17 | |||
18 | (define answer-5 |
||
19 | 2 | Noppi | (let ([n (* 11 13 15 16 17 19)]) |
20 | (let loop ([i n]) |
||
21 | 1 | Noppi | (if (and |
22 | (zero? (mod i 12)) |
||
23 | (zero? (mod i 14)) |
||
24 | (zero? (mod i 18)) |
||
25 | (zero? (mod i 20))) |
||
26 | i |
||
27 | (loop (+ i n)))))) |
||
28 | |||
29 | (printf "5: ~D~%" answer-5) |
||
30 | ``` |