// 2011/03/22 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	while(!cin.eof()){
		string str;
		getline(cin, str);

		if(str.empty())
			continue;

		istringstream ist(str);
		int p, q;
		ist >> p >> q;

		int syo[100];
		int ama[100];
		int m = -1;
		int n = -1;
		for(int i=0; i<100; i++){
			p *= 10;
			syo[i] = p/q;
			ama[i] = p%q;

			if(ama[i]==0){
				cout << syo[i] << endl;
				break;
			}

			for(int j=0; j<i; j++)
				if(syo[j]==syo[i]&&ama[j]==ama[i]){
					m = j;
					n = i;
					break;
				}

			if(m!=-1){
				cout << endl;
				for(int j=0; j<m; j++)  cout << ' ';
				for(int j=m; j<n; j++)  cout << '^';
				cout << endl;
				break;
			}

			cout << syo[i];
			p = ama[i];
		}
	}

	return 0;
}