def odai632(a, b) a %= b return 0 if a == 0 h = {} loop do a *= 10 while a < b a %= b return h.size if h[a] h[a] = true end end %w[1/3 10/2 988027/983 919/870473 1223/1476221 99998360006603/9999901 123412345/999999999 1234/555 17941970723/5711177472].map do |e| a, b = e.split('/').map(&:to_i) p [a, b, odai632(a, b)] end
Standard input is empty
[1, 3, 1] [10, 2, 0] [988027, 983, 884] [919, 870473, 48915] [1223, 1476221, 110562] [99998360006603, 9999901, 1799242] [123412345, 999999999, 9] [1234, 555, 3] [17941970723, 5711177472, 1417]