Problem 3 » 履歴 » バージョン 1
Noppi, 2023/12/27 01:33
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 3]] |
||
3 | |||
4 | ```scheme |
||
5 | #!r6rs |
||
6 | #!chezscheme |
||
7 | |||
8 | (import (chezscheme)) |
||
9 | |||
10 | (define answer-3 |
||
11 | (let* ((n 600851475143) |
||
12 | (check-max (isqrt n))) |
||
13 | (let loop ((current 3) (rest n) (max-prime 1)) |
||
14 | (cond |
||
15 | [(< check-max current) max-prime] |
||
16 | [(zero? (mod rest current)) |
||
17 | (loop current (div rest current) current)] |
||
18 | [else (loop (+ current 2) rest max-prime)])))) |
||
19 | |||
20 | (printf "3: ~D~%" answer-3) |
||
21 | ``` |