#include<iostream>
#include<map>

using namespace std;

void print(int from, int to){
  cout << endl;
  for(int i = 0; i < from; i++) cout << " ";
  for(int i = from; i < to; i++) cout << "^";
}

int main(){

  int p,q;
  while(cin >> p >> q){
    map<int,int> M;
    int cnt = 0;
    p*=10;

    while(1){
      int a = p/q;
      int b = p%q;

      cout << a;
      if(M[b] == 0) M[b] = ++cnt;
      else{
	print(M[b], ++cnt);
	break;
      }
      
      if(b == 0) break;
      
      p = b*10;
    }
    cout << endl;
  }
  return 0;
}