#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstdio>
using namespace std;
typedef long long Int;


int main(){
	int p, q;
	while(~scanf("%d%d", &p, &q)){
		set<int> nums;
		vector<int> ans, ms;
		p *= 10;
		for(int i = 0;i < 800;i++){
			if(nums.count(p) || p == 0)break;
			ms.push_back(p);
			nums.insert(p);
			ans.push_back(p / q);
			p %= q;
			p *= 10;
		}
		for(int i = 0;i < ans.size();i++){
			cout << ans[i];
		}                  cout << endl;
		if(p != 0){
			char x = ' ';
			for(int i = 0;i < ans.size();i++){
				if(ms[i] == p)x = '^';
				cout << x;
			}             cout << endl;
		}
	}
	return 0;
}