Last active
August 29, 2015 14:02
-
-
Save Manume/e16dbcbc66a2df59f524 to your computer and use it in GitHub Desktop.
Find the biggest primefactor using class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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