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

#define M 1000003

int main() {
	map<int, int> qu;
	int p, q, r, c, s, t;
	bool cycle;
	while(cin >> p >> q) {
		qu.clear(); c = 0; cycle = true;
		while(qu.count(p)==0) {
			qu[p] = c++; p*=10;
			r = p/q;
			cout << r;
			if(r>0) {
				p %= q;
				if(p==0) {
					cycle = false;
					break;
				}
			}
		}
		cout << endl;
		if(cycle) {
			s = qu[p]; t = c;
			for(int i=0; i<s; ++i) cout << " ";
			for(int i=s; i<t; ++i) cout << "^";
			cout << endl;
		}
	}
}