Skip to content

Instantly share code, notes, and snippets.

@opamp
Created September 2, 2011 18:07
Show Gist options
  • Save opamp/1189343 to your computer and use it in GitHub Desktop.
Save opamp/1189343 to your computer and use it in GitHub Desktop.
projectEuler3
#!/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