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

void print(int a, int b){
	cout << endl;
	for(int i = 0;i < a;i++)cout << " ";
	for(int i = a;i < b;i++)cout << "^";
}

int main(){
	int p, q;
	while(cin >> p >> q){
		map<int, int> m;
		int cnt = 0;
		bool f = false;
		while(1){
			int a = p/q;
			int b = p%q;
			p = b * 10;
			if(f)cout << a;
			f = true;
			if(!b)break;
			
			if(!m[b])m[b] = ++cnt;
			else {print(m[b]-1, cnt);break;}
		}
		cout << endl;
	}
	return 0;
}