-
-
Save opamp/1189343 to your computer and use it in GitHub Desktop.
projectEuler3
This file contains 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
#!/usr/bin/env ruby | |
#-*- encoding:utf-8 -*- | |
=begin | |
Question. | |
The prime factors of 13195 are 5, 7, 13 and 29. | |
What is the largest prime factor of the number 600851475143 ? | |
超へっぽこコード クラスにした意味がわからない。 | |
=end | |
class Soinsu | |
attr_reader :So | |
attr_reader :n | |
def initialize(n) | |
@n = n | |
x = 2 | |
ans = Array.new | |
ka = @n | |
loop do | |
if ka % x == 0 then | |
ans << x | |
ka = ka / x | |
next | |
else | |
x+=1 | |
end | |
if ka == 1 then | |
break | |
end | |
end | |
@So = ans | |
end | |
end | |
a = Soinsu.new 600851475143 | |
puts a.So[a.So.size - 1].to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment