#include <iostream>
#include <map>
using namespace std;

main(){
  int p, q;
  while(cin >> p >> q){
    map<int, int> pos;
    p = p%q * 10;
    for(int i=0;;i++){
      cout << p/q;
      int tmp = p%q;
      if(tmp == 0){
	cout << endl;
	break;
      }
      p = tmp*10;
      if(pos.find(p) != pos.end()){
	cout << endl;
	for(int j=0;j<=i;j++){
	  if(pos[p]<j) cout << '^';
	  else cout << ' ';
	}
	cout << endl;
	break;
      }
      pos[p] = i;
    }
  }
  return 0;
}