Skip to content

Instantly share code, notes, and snippets.

@santiago
Created July 30, 2010 01:43
Show Gist options
  • Save santiago/499693 to your computer and use it in GitHub Desktop.
Save santiago/499693 to your computer and use it in GitHub Desktop.
a=600851475143
#a=11351340
last_prime= 2
counter= 2
prime_factors= []
factoring= 1
def factor_by(number, factor)
if number.modulo(factor) == 0
@count= @count.nil? ? 1 : @count+1
factor_by(number/factor, factor)
end
return @count;
end
if a.modulo(2) == 0
prime_factors=[2]
@count= nil
factoring= factoring*(2**factor_by(a,2))
counter= 3
end
while(factoring != a) do
next_me= false
if a.modulo(counter) == 0
prime_factors.each do |p|
if counter.modulo(p) == 0
counter= counter+1
next_me=true
end
end
next if next_me
@count= nil
factoring= factoring*(counter**factor_by(a,counter))
last_prime = counter
prime_factors << last_prime
end
counter= counter+1
end
p prime_factors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment