Skip to content

Instantly share code, notes, and snippets.

@Manume
Last active August 29, 2015 14:02
Show Gist options
  • Save Manume/e16dbcbc66a2df59f524 to your computer and use it in GitHub Desktop.
Save Manume/e16dbcbc66a2df59f524 to your computer and use it in GitHub Desktop.
Find the biggest primefactor using class
#to find the biggest prime number
class Prime
def initialize(num)
puts "input value is #{num}"
end
def primefactor(n)
i=2
largest=0
while(i<=n)
if(n%i==0)
while(n%i==0)
n=n/i
largest=i
i+=1
end
end
i+=1
end
return largest
end
end
obj=Prime.new(600851475143)
big=obj.primefactor(600851475143)
puts "the biggest prime number is #{big} "
=begin
output:
the biggest prime number is 6857
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment