$stdin.each do |input|
  a, b = input.split.map(&:to_i)
  q = ""
  r = []
  i, j = 0, nil
  loop do
    a *= 10
    q << (a / b).to_s
    _r = a % b
    j = nil
    break if _r == 0
    j = r.index _r
    break if j
    a = _r
    r << _r
    i += 1
  end
  puts q
  if j
    puts " " * (j + 1) + "^" * (i - j)
  end
end