Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active December 16, 2015 11:59
Show Gist options
  • Select an option

  • Save thinkphp/5431087 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/5431087 to your computer and use it in GitHub Desktop.
Project Euler Problem 3 in Common Lisp
;Project Euler Problem 3
;Largest prime factor
;The prime factors of 13195 are 5, 7, 13 and 29.
;What is the largest prime factor of the number 600851475143 ?
(defun largest (N)
(setf i 2)
(prog (fac)
start
(if (<= (* i i) N)
(if (= (REM N i) 0) (and (setf N (/ N i)) (setf fac (cons i fac)) ) (setf i (+ i 1))
)
(if (/= N 1) (and (setf fac (cons N fac)) (return (last (reverse fac))) ))
)
(go start)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment