fork download
  1. def odai632(a, b)
  2. a %= b
  3. return 0 if a == 0
  4. h = {}
  5. loop do
  6. a *= 10 while a < b
  7. a %= b
  8. return h.size if h[a]
  9. h[a] = true
  10. end
  11. end
  12.  
  13. %w[1/3
  14. 10/2
  15. 988027/983
  16. 919/870473
  17. 1223/1476221
  18. 99998360006603/9999901
  19. 123412345/999999999
  20. 1234/555
  21. 17941970723/5711177472].map do |e|
  22. a, b = e.split('/').map(&:to_i)
  23. p [a, b, odai632(a, b)]
  24. end
  25.  
Success #stdin #stdout 1.06s 144832KB
stdin
Standard input is empty
stdout
[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]