Comment detail

ダブル完全数 (Nested Flatten)
やはりこういうのはRubyだと遅い。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def divisors(n)
  ret = []
  1.upto(n) do |i|
    ret << i if n % i == 0
  end
  ret
end

def double_complete_number?(n)
  n * 3 == divisors(n).inject(0){|s,x| s+x}
end

1.upto(10000){|i| puts i if double_complete_number?(i) }

Index

Feed

Other

Link

Pathtraq

loading...