#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int p, q;
  while (cin >> p >> q) {
    map<int, int> mp;
    int pos = 0, l = -1, r = -1;
    string digit = "";
    bool finite = false;
    while (true) {
      p *= 10;
      if (mp.find(p) != mp.end()) {
        l = mp[p], r = pos;
        break;
      }
      mp[p] = pos++;
      digit += p / q + '0';
      p %= q;
      if (p == 0) {
        finite = true;
        break;
      }
    }
    cout << digit << endl;
    if (!finite) cout << string(l, ' ') << string(r - l, '^') << endl;
  }

  return 0;
}
