#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int a, b;
	while (cin >> a >> b) {
		bool b1 = 0;
		a *= 10;
		vector<int>v;
		while (1) {
			if (a == 0)goto heaven;
			for (int i : v)if (i == a)goto hell;
			v.push_back(a);
			cout << a / b;
			a = a % b * 10;
		}
	hell:cout << endl;
		for0(i, v.size()) {
			if (!b1 && v[i] != a)cout << ' ';
			if (b1 || v[i] == a) {
				cout << '^';
				b1 = 1;
			}
		}
	heaven:cout << endl;
	}
}
