#include <iostream>
using namespace std;
int r[82];
int main()
{
  int p,q;
  while(cin >> p >> q){
    int i=0;
    p %= q;
    for(;;){
      cout << p*10/q;
      p = p*10%q;
      if(p == 0) {
	cout << endl;
	break;
      }else{
	int j;
	for(j=0;j<i;j++){
	  if(r[j] == p) break;
	}
	if(j == i) r[i++] = p;
	else{
	  cout << endl;
	  int k;
	  for(k=0;k<=i;k++){
	    if(k>j) cout << "^";
	    else cout << " ";
	  }
	  cout << endl;
	  break;
	}
      }
    }
  }
  return 0;
}