#include<cstdio>

#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

const int INF=1<<29;

int main(){
	for(int p,q;~scanf("%d%d",&p,&q);){
		static int mod[1000000];
		rep(i,q)	mod[i]=-1;
		mod[p]=0;

		rep(i,INF){
			p*=10;
			putchar(p/q+'0');
			p%=q;

			if(p==0){	// finite decimal
				putchar('\n');
				break;
			}
			if(~mod[p]){	// repeating decimal
				putchar('\n');
				rep(j,mod[p])		putchar(' ');
				rep(j,i-mod[p]+1)	putchar('^');
				putchar('\n');
				break;
			}
			mod[p]=i+1;
		}
	}

	return 0;
}