操作
Problem 10 » 履歴 » リビジョン 1
リビジョン 1/8
| 次 »
Noppi, 2023/12/27 01:59
Problem 10¶
#!r6rs
#!chezscheme
(import (chezscheme))
(define answer-10
(let ((table (make-vector 2000001 #t))
(count (isqrt 2000000)))
(vector-set! table 0 #f)
(vector-set! table 1 #f)
(let loop1 ((index 2))
(cond
[(< count index)
(let loop2 ((index 0) (result 0))
(cond
[(< 2000000 index) result]
[(vector-ref table index)
(loop2 (add1 index) (+ result index))]
[else (loop2 (add1 index) result)]))]
[(vector-ref table index)
(let loop3 ((current (* index 2)))
(cond
[(< 2000000 current)
(loop1 (add1 index))]
[else
(vector-set! table current #f)
(loop3 (+ current index))]))]
[else (loop1 (add1 index))]))))
(printf "10: ~D~%" answer-10)
Noppi が2023/12/27に更新 · 1件の履歴