#include <iostream>
#include <cstdio>
#include <iomanip>

using namespace std;

const int limit = 85;

void Print(const string &s)
{
    int st, end;

    for (int i = 0; i < s.size(); i++) {  // 始点
        for (int k = 1; i + k < s.size() / 2; k++) {  // 数字幅
            bool flag = true;
            string tmp = s.substr(i, k);
            st = i + k;

            while (st + k < s.size()) {
                if (s.substr(st, k) != tmp) {
                    flag = false;
                    break;
                }
                st += k;
            }

            if (flag) {
                cout << s.substr(0, i) << tmp << endl;
                for (int l = 0; l < i; l++)
                    putchar(' ');
                for (int l = 0; l < tmp.size(); l++)
                    putchar('^');
                putchar('\n');

                return ;
            }
        }
    }
}

int main()
{
    int p, q;

    while (cin >> p >> q) {
        string s;
        int quotient, surplus;
        bool flag = false;

        for (int i = 0; i < limit; i++) {
            p *= 10;
            quotient = p / q;
            surplus  = p % q;

            s.push_back(quotient + '0');
            if (surplus == 0) {
                flag = true;
                break;
            }

            p = surplus;
        }
        if (flag)
            cout << s << endl;
        else
            Print(s);
    }

    return 0;
}