Skip to content

Instantly share code, notes, and snippets.

@nbryan
Created June 23, 2009 03:16
Show Gist options
  • Select an option

  • Save nbryan/134334 to your computer and use it in GitHub Desktop.

Select an option

Save nbryan/134334 to your computer and use it in GitHub Desktop.
require "mathn"
number, primes, factors = 600851475143, Prime.instance, []
for i in primes
if number % i == 0
factors << i
number = number / i
redo
elsif i > Math.sqrt(number)
factors << number if number > 1
break
end
end
print "Prime factors: #{factors}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment