#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(int p, int q) {
    map<int,int> r;
    int rr;
    vector<int> d;
    r[p] = -1;
    for (int i=0; ; ++i) {
        p *= 10;
        d.push_back(p / q);
        p %= q;
        if (p == 0) {
            for (int x: d) cout << x;
            cout << endl;
            return;
        }
        if (r.count(p)) {
            rr = r[p];
            break;
        }
        r[p] = i;
    }

    for (int x: d) cout << x;
    cout << endl;
    for (int i=0; i<(int)d.size(); ++i) {
        cout << (rr < i ? "^": " ");
    }
    cout << endl;
}

int main() {
    ll p, q;
    while (cin >> p >> q) {
        solve(p, q);
    }
    return 0;
}
