#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st;
	while (getline(cin,st)) {
		long long int p = stoi(st.substr(0, st.find(" ")));
		long long int q = stoi(st.substr(st.find(" ") + 1));
		vector<int>vs;
		for (int i = 0; i < 10000; ++i) {
			p *= 10;
			vs.push_back(p / q);
			p %= q;
			if (!p)break;
		}
		if (vs.size() != 10000) {
			for (auto v : vs) {
				cout << v;
			}
			cout << endl;
		}
		else {
			int roop = 1;
			for (; roop <=80; ++roop) {
				bool flag = true;
				for (int i = 2000; i < 8000; ++i) {
					if (vs[i] == vs[i + roop]) {

					}
					else {
						flag = false;
					}
				}
				if (flag)break;
			}
			int start = 100;
			for (; start >= 0; --start) {
				if (vs[start] == vs[start + roop]) {

				}
				else {
					start;
					break;
				}
			}
			for (int i = 0; i <= start+roop; ++i) {
				cout << vs[i];
			}
			cout << endl;
			for (int i = 0; i <= start + roop; ++i) {
				if (i <=start)cout << " ";
				else cout << "^";
			}
			cout << endl;
		}
	}
	return 0;
}