#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define it vector<int>::iterator
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		a%=b;
		vi amr;
		while(1){
			a*=10;
			bool h=false;
			cout<<a/b;
			a%=b;
			if(!a){
				cout<<endl;
				break;
			}
			rep(i,amr.size())if(amr[i]==a){
				cout<<endl;
				rep(j,i+1)cout<<" ";
				rep(j,amr.size()-i)cout<<"^";
				cout<<endl;
				h=true;
				break;
			}
			if(h)break;
			amr.pb(a);
		}
	}
}