#include <iostream>
using namespace std;

int main() {
	int a,b,c[82],i,j,k,f;
	while(cin >> b >> a) {
		b=b*10; c[0]=b;
		for (k=0;k<80;k++) {
			cout << b/a;  
			b=(b-a*(b/a))*10; f=0;
			for (i=0;i<k+1;i++) if (b==c[i] || b==0)  { f=1; break;}
			if (f==1) break;
			c[k+1]=b;
		}
		cout << endl;
		if (b>0) { 
			for (j=0;j<k+1;j++) if (j<i) cout << ' '; else cout << '^'; 
			cout << endl;
		}
	}
return 0;
}