# coreBugZJ

## PRIME1 - SPOJ 2. Prime Generator

LISP SBCL

1(defconstant +max-size+ 35000)
2(defvar *prime* (make-array +max-size+ :initial-element t))
3(defvar *prime-size* 0)
4
5(defun init-prime()
6 (do
7 ((i 2 (1+ i)))
8 ((>= i +max-size+))
9 (when (elt *prime* i)
10 (setf (elt *prime* *prime-size*) i)
11 (incf *prime-size*)
12 (do
13 ((j (+ i i) (+ j i)))
14 ((>= j +max-size+))
15 (setf (elt *prime* j) nil)))))
16
17(defconstant +max-len+ 100009)
18(defvar *ans* (make-array +max-len+ :initial-element t))
19(defvar *ans-size*)
20
21(defun solve(m n)
22 (when (< m 2) (setf m 2))
23 (when (> m n)
24 (format t "~%")
25 (return-from solve nil))
26 (setf *ans-size* (1+ (- n m)))
27 (dotimes (i *prime-size*)
28 (let* ((p (elt *prime* i))
29 (b (* (floor (/ (1- (+ m p)) p)) p)))
30 (do ((x (if (> b p) b (+ p p)) (+ x p)))
31 ((> x n))
32 (setf (elt *ans* (- x m)) nil))))
33 (dotimes (i *ans-size*)
34 (if (elt *ans* i)
35 (format t "~d~%" (+ m i))
36 (setf (elt *ans* i) t)))
37 (format t "~%" ))
38
39(init-prime)