#include <iostream>
#include <map>
#include <vector>
#include <cstring>

using namespace std;

const int L = 80;

int main(){
	int p, q, d;
	char a[L];
	while(cin >> p >> q){
		map<int, int> t;
		memset(a, 0, sizeof(a));
		d = 0;
		p *= 10;
		while(p != 0 && !t[p]){
			int x = p / q;
			t[p] = d;
			a[d] = (char)(x + '0');
			p -= x * q;
			p *= 10;
			++d;
		}
		cout << a << endl;

		if(p != 0){
			for(int i = 0;i < t[p];++i){
				cout << " ";
			}
			for(int i = t[p];i < d;++i){
				cout << "^";
			}
			cout << endl;
		}
	}
	return 0;
}