#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int p, q;
        if(!(cin >> p >> q))
            return 0;

        bool repeat = true;
        int i = 0;
        map<int, int> rest;
        rest.insert(make_pair(p, 0));
        for(;;){
            p *= 10;
            int a = p / q;
            cout << a;
            p %= q;
            if(p == 0){
                repeat = false;
                break;
            }
            if(rest.find(p) != rest.end())
                break;
            ++ i;
            rest.insert(make_pair(p, i));
        }

        cout << endl;
        if(repeat){
            int x = rest.find(p)->second;
            cout << string(x, ' ') << string(i-x+1, '^') << endl;
        }
    }
}