//34
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  for(int p,q;cin>>p>>q;){
    vector<int> v;
    p*=10;
    for(;;){
      v.push_back(p);
      cout<<p/q;
      p=(p%q)*10;
      if(p==0){
	cout<<endl;
	break;
      }else if(find(v.begin(),v.end(),p)!=v.end()){
	int i=find(v.begin(),v.end(),p)-v.begin();
	cout<<endl;
	cout<<string(i,' ')<<string(v.size()-i,'^')<<endl;
	break;
      }
    }
  }
  return 0;
}