Skip to content

Instantly share code, notes, and snippets.

@tshatrov
Last active March 25, 2019 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshatrov/86ecefc504b4daad43d9d670f3387551 to your computer and use it in GitHub Desktop.
Save tshatrov/86ecefc504b4daad43d9d670f3387551 to your computer and use it in GitHub Desktop.
(let* ((target 600851475143) ;; number to factorize
(n (floor (sqrt target))) ;; size of sieve
)
(loop named outer
with arr = (make-array n :initial-element nil)
for i from 2 below n
unless (aref arr i)
do (loop for j from i below n by i do (setf (aref arr j) i))
(loop while (zerop (mod target i))
do (format t "~a ~a~%" target i)
if (= target i) do (return-from outer target) else do (setf target (/ target i)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment