#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
using namespace std;

int main() {
	int a, b; while (cin >> a >> b) {
		int c[100], d = -1;
		int s = 0, g = 0;
		while (d++, 1) {
			a *= 10;
			cout << a / b;
			c[d] = a%b;
			if (a%b == 0) {
				cout << endl;
				goto q;
			}
			for (int e = 0; e < d; e++) {
				if (c[e] == c[d]) {
					s = e; g = d;
					goto l;
				}
			}
			a -= (a / b)*b;
		}
	l:;
		cout << endl;
		for (int i = 0; i <= g; i++) {
			if (s >= i)cout << ' ';
			else cout << '^';
		}
		cout << endl;
	q:;
	}
}