
import std.stdio, std.math, std.conv;

void main() {
  for(int a, b; readf("%d %d\n", &a, &b);) {
    int[int] used;
    int len = 0;
    int c;
    bool first = true;
    a %= b;  
    do {
      c = a % b;
      if (first) first = false;
      else write(a / b);
      if (c == 0) break;      
      if (c in used) break;
      else {
        used[c] = len;
        a = c * 10;
      }
      len++;
    } while(true);
    writeln;
    if (c != 0) {
      for(int i = 0; i <= used[c] - 1; i++) write(" ");
      for(int i = used[c] + 1; i <= len; i++) write("^");
      writeln;
    }
  }
}