#include <array>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

void solve(int p, int q)
{
    unordered_map<int, int> r_idx;

    int r = 10 * p;

    for(int i = 0; ; ++i) {
        r_idx[r] = i;

        int digit = r / q;
        printf("%d", digit);

        r = 10 * (r % q);

        if(r == 0) {
            puts("");
            return;
        }

        if(r_idx.find(r) != r_idx.end()) {
            puts("");

            int idx_begin = r_idx[r];
            REP(_, idx_begin) {
                putchar(' ');
            }
            REP(_, i+1 - idx_begin) {
                putchar('^');
            }
            puts("");

            return;
        }
    }
}

int main()
{
    char buf[1024];
    while(fgets(buf, sizeof(buf), stdin)) {
        int p, q;
        sscanf(buf, "%d %d\n", &p, &q);
        //printf("%d %d\n", p, q);

        solve(p, q);
    }

    return 0;
}