8 lines
300 B
Common Lisp
8 lines
300 B
Common Lisp
;;; Recursive algorithm
|
|
(defun factor (n)
|
|
"Return a list of factors of N."
|
|
(when (> n 1)
|
|
(loop with max-d = (isqrt n)
|
|
for d = 2 then (if (evenp d) (+ d 1) (+ d 2)) do
|
|
(cond ((> d max-d) (return (list n))) ; n is prime
|
|
((zerop (rem n d)) (return (cons d (factor (truncate n d)))))))))
|