20 lines
729 B
Common Lisp
20 lines
729 B
Common Lisp
(defun factors (n &aux (lows '()) (highs '()))
|
|
(do ((limit (1+ (isqrt n))) (factor 1 (1+ factor)))
|
|
((= factor limit)
|
|
(when (= n (* limit limit))
|
|
(push limit highs))
|
|
(remove-duplicates (nreconc lows highs)))
|
|
(multiple-value-bind (quotient remainder) (floor n factor)
|
|
(when (zerop remainder)
|
|
(push factor lows)
|
|
(push quotient highs)))))
|
|
|
|
(defun anti-prime ()
|
|
(format t "The first 20 anti-primes are :~%")
|
|
(do ((dmax 0) (c 0) (i 0 (1+ i)))
|
|
((= c 20))
|
|
(setf facts (list-length (factors i)))
|
|
(when (< dmax facts)
|
|
(format t "~d " i)
|
|
(setq dmax facts)
|
|
(incf c))))
|