Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Integer
- def divis_by?(n)
- if n != 0
- self.to_f / n == (self.to_f / n).to_i
- end
- end
- def factors
- f = [1]
- for i in 2..self-1
- f.push i if self.divis_by?(i)
- end
- f.push self
- f
- end
- end
- i = 1
- add = 2
- while i.factors.length <= 500
- puts "#{i} #{i.factors.length}"
- i += add
- add += 1
- end
- puts "First triangle number with over 500 factors: #{i}"
Add Comment
Please, Sign In to add comment