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