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

int digit(int n) {
  int len = 0;
  for(; n > 0; n /= 10) len++;
  return len;
}

void main() {
  for(long a, b; readf("%d %d\n", &a, &b);) {
    int[long] used;
    int len = 0;
    long c;
    int[] ans;
    bool divisible = false;

    if (a < b) a *= 10;
  
    do {
      if (a == 0) {divisible = true; break;}
      c = a % b;
      write(a / b);
      if (c in used) break;
      else {
        used[c] = len;
        a = c * 10;
      }
      len++;
    } while(true);
    writeln;
  
    if (!divisible) {
      int d = digit(used[c]);
      for(int i = 0; i <= d; i++) write(" ");
      for(int i = d + 1; i <= len; i++) write("^");
      writeln;
    }
  }
}