#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
	int p,q;
	scanf("%d%d",&p,&q);
	int flg[100000] = {0};
	p %= q;	
	for(int i = 1;;i++){
			
		if(p == 0){
			break;
		}
		p %= q;	
		if(flg[p] != 0){
			cout<<endl;
			for(int j = 0;j < flg[p];j++)cout<<" ";
			for(int j = flg[p];j < i;j++)cout<<"^";	
			break;
		}
		flg[p] = i;
		cout<<p;
		p *= 10;
		
	}
	cout<<endl;
	return 0;
}