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

int main() {
	int p, q;

	while(cin >> p >> q) {
		vector<int> v;
		bool flag = true;

		p %= q;
		while(flag){
			p *= 10;
			cout << p / q;
			p %= q;
			if(p == 0) {
				cout << endl;
				break;
			}
			for(int i = 0; i < v.size(); i++) {
				if(p == v[i]) {
					flag = false;
					cout << endl;
					for(int j = 0; j <= i; j++)
						cout << " ";
					for(int j = i + 1; j < v.size() + 1; j++)
						cout << "^";
					cout << endl;
				}
			}
			v.push_back(p);
		}
	}

	return 0;
}