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

std::string func(std::string str,int x){
  std::string ret;
	while( --x ){
		ret+=str;
	}
	return ret;
}
int main(){
	std::vector<int>::iterator Result;
	std::vector<int> mod;
 	int p,q;
  while(std::cin>>p>>q){
		mod.clear();
		bool End=false;
		while(1){
			if(p==0)break;
			std::cout<<(p*10)/q;
			mod.push_back(p);
			if(mod.size()>80)break;
			if( ( Result=std::find(mod.begin(), mod.end(), (p*10)%q ) ) !=mod.end() ){End=true;break;}
			p=(p*10)%q;
		}
		std::cout<<std::endl;
		if(End)std::cout<<func(" ",Result-mod.begin()+1)<<func("^",mod.size()-(Result-mod.begin())+1)<<std::endl;
	}
	return 0;
}