Skip to content

Instantly share code, notes, and snippets.

@fogus
Created September 9, 2009 18:31
Show Gist options
  • Save fogus/183950 to your computer and use it in GitHub Desktop.
Save fogus/183950 to your computer and use it in GitHub Desktop.
;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)
(- d 1)
(recur
(#(if (zero? (rem % d))
(recur (/ % d))
%)
n)
(inc d))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment