#include "bits/stdc++.h"

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
int ans[11][11]={};

int main(){
    int a,b;
    while(cin>>a>>b){
        static int used[10000001]={};
        memset(used, -1, sizeof(used));
        string ans="";
        int c=0;
        a*=10;
        while(1){
            int x=a/b;
            int y=a%b;
            ans+='0'+x;
            if(y==0){cout<<ans<<endl;break;}
            if(used[y]!=-1){
                cout<<ans<<endl;
                rep(i,used[y]+1)cout<<" ";
                rep(i,ans.size()-1-used[y])cout<<'^';
                cout<<endl;
                break;
            }
            used[y]=c;
            a-=b*x;
            c++;
            a*=10;
        }
    }
    
}