#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int main(void){
    int p,q;
    while(EOF != scanf("%d%d",&p,&q)){
        map< int ,int > flg;
        
        //cout<<<<endl;
        for(int i = 1;;i++){
            int x = p / q;

            if(i!=1)cout << x;
            if(p % q == 0){
                break;
            }
            p -= x*q;
            p *= 10;    
            
            
            //cout<<p<<"-"<<x*q<<endl;
            if(flg[p] != 0){
                cout<<endl;
                for(int j = 0;j < flg[p]-1;j++)cout<<" ";
                for(int j = flg[p];j < i;j++)cout<<"^";   
                break;
            }
            flg[p] = i;

             
        }
        cout<<endl;
    }
    return 0;
}