#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


int main()
{
	int p, q;
	while (scanf("%d %d", &p, &q) != EOF)
	{
		map<int, int> rem;
		int i;
		p *= 10;
		for (i = 1; p != 0 && !rem[p]; ++i)
		{
			rem[p] = i;
			printf("%d", p/q);
			p %= q;
			p *= 10;
		}
		printf("\n");
		if (p)
		{
			for (int j = 1; j < i; ++j)
			{
				if (j < rem[p])
					printf(" ");
				else
					printf("^");
			}
			printf("\n");
		}
	}

	return 0;
}