1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

エラトステネスの篩

Last updated at Posted at 2012-08-28

書いてた人がいたので…

prime.scm
(use srfi-1)
(define (prime n)
  (let loop ((lst (iota (- n 1) 2))(result '()))
	(let ((solve (cons (car lst) result)))
	  (if (< (last lst) (* (car solve) (car solve)))
		(append (reverse result) lst)
		(loop (remove (^(x)(zero? (remainder x (car lst)))) lst) solve)))))
;(time (prime 10000))
; real   0.011
; user   0.010
; sys    0.000
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?