#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	int p,q;
	while(std::cin>>p>>q){
		std::vector<int>am;
		int it;
		p*=10;
		while(1){
			std::cout<<p/q;
			it=std::find(am.begin(),am.end(),p%q)-am.begin();
			if(it==am.size())am.push_back(p%q);
			else break;
			if(p%q==0)goto end;
			p=p%q*10;
		}
		std::cout<<std::endl;
		for(int i=0;i<=am.size();i++){
			if(i>=it)std::cout<<'^';
			else std::cout<<" ";
		}
		end:;
		std::cout<<std::endl;
	}
	return 0;
}