Skip to content

Instantly share code, notes, and snippets.

@50n1cd347h9
Last active April 29, 2024 09:07
Show Gist options
  • Save 50n1cd347h9/592273cb57cf47312ca2955e5518f4a3 to your computer and use it in GitHub Desktop.
Save 50n1cd347h9/592273cb57cf47312ca2955e5518f4a3 to your computer and use it in GitHub Desktop.
素因数分解
(defun bunkai (n)
(let ((limit (floor (sqrt n))))
(labels ((f (n divisor acc)
(if (and (not (= 1 n))
(<= divisor limit))
(if (zerop (mod n divisor))
(f (/ n divisor)
divisor
(cons divisor acc))
(f n
(1+ divisor)
acc))
(remove 1 (cons n acc)))))
(f n 2 ()))))
(compile 'bunkai)
(prin1 (bunkai (read)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment