require 'prime' a = gets.to_i b = gets.to_i g = a.gcd(b) a/=g b/=g if(a%b==0) puts (a/b)%10 exit end pd = Prime.prime_division(b).map(&:first) pd -= [2,5] if(pd.empty?) r = a.to_r / b while r % 1 > 0 r *= 10 end puts (r % 10).to_i else puts -1 end