to site top page

Problem 26 - Project Euler

loop_count = 0
ans = 0
for n in 1..999
    count_2 = count_5 = 0
    buf = n
    while buf % 2 == 0 do
        count_2 += 1
        buf /= 2
    end
    while buf % 5 == 0 do
        count_5 += 1
        buf /= 5
    end
    if (count_2 == 0)&&(count_5 == 0)
        dividend = 10**(n.to_s.length)
    else
        dividend = (2 ** count_5) * (5 ** count_2)
    end
    modulus = n / (2 ** count_2) / (5 ** count_5)
    next if modulus == 1
    remainder = dividend % modulus
    dividend = remainder * 10
    buf = 1
    while remainder != dividend % modulus
        buf += 1
        dividend = (dividend % modulus) * 10
    end
    if buf > loop_count
        loop_count = buf
        ans = n
    end
end
puts ans

can't load my result

最近の記事(5件分)

する事

そのうち記事にするかもリスト

欲しい本