#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
int main(void){
  int p,q;
  while(cin>>p>>q){
    vector<int> mod;
    mod.push_back(p);
    int count=0;
    while(true){
      p*=10;
      cout << p/q;
      p=p%q;
      if(!p){
        cout<<endl;
        break;
      }
      if(find(mod.begin(),mod.end(),p)!=mod.end()){
        int div = distance(mod.begin(),find(mod.begin(),mod.end(),p));
        cout<<endl;
        REP(i,div) cout<<' ';
        REP(i,count-div+1) cout<<'^';
        cout<<endl;
        break;
      }
      mod.push_back(p);
      count++;
    }
  }
  return  0;
}