#include <iostream>

using namespace std;

const int N = 1000000;

main(){
  int p, q;
  while(cin >> p >> q){
    bool used[N];
    int pos[N];
    fill(used, used+N, false);
    //cout << p << ' ' << q << ' ' << p%q << endl;
    p = p%q * 10;
    for(int i=0;;i++){
      //cout << "=========== " << p << ' ' << q << ' ' << p%q << endl;
      cout << p/q;
      int tmp = p%q;
      if(i >= 80 || tmp == 0){
	cout << endl;
	break;
      }
      p = tmp*10;
      //cout << "############ " << p << ' ' << q << ' ' << p%q << endl;
      if(used[p]){
	cout << endl;
	for(int j=0;j<=i;j++){
	  if(j<=pos[p]) cout << ' ';
	  else cout << '^';
	}
	cout << endl;
	break;
      }
      used[p] = true;
      pos[p] = i;
    }
  }
  return 0;
}