#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
typedef long long ll;
typedef pair<ll,ll> pll;


pll foo(ll a,ll b){
	return pll((a*10)/b,(a*10)%b);
}



int main(){
	ll p,q;
	while(cin>>p>>q){
		string ans;
		vector<ll> v;
		while(1){
			v.push_back(p);
			pll t=foo(p,q);
			stringstream ss;
			ss<<ans;
			ss<<t.first;
			ss>>ans;
			p=t.S;
			if(p==0){
				cout<<ans<<endl;
				break;
			}
			bool f=false;
			int pos=0;
			rep(i,v.size()){
				if(p==v[i]){
					f=true;
					pos=i;
				}
			}
			if(f){
				cout<<ans<<endl;
				rep(i,ans.size()){
					if(i>=pos) cout<<"^";
					else cout<<" ";
				}
				cout<<endl;
				break;
			}
		}
	}
}