Lisp Count Factors
(defun count-factors (n)
(let ((count 0)
(i 1))
(loop while (< (* i i) n)
do (progn
(when (zerop (mod n i))
(incf count 2))
(incf i)))
(when (= (* i i) n)
(incf count))
count))
This checks divisors in pairs up to the square root, which keeps the work much smaller than testing every number.