Last active
April 29, 2024 09:07
-
-
Save 50n1cd347h9/592273cb57cf47312ca2955e5518f4a3 to your computer and use it in GitHub Desktop.
素因数分解
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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