#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){

	int p,q,start,end;
	int* table = new int[1000000];
	bool FLG;

	while(scanf("%d %d",&p,&q)!=EOF){
		for(int i=0; i < q;i++)table[i] = -1;

		FLG = false;

		table[p] = 0;

		for(int i=1;i<=80;i++){
			p = 10*p;
			printf("%d",p/q);
			p = p%q;
			if(p == 0)break;
			if(table[p] == -1){
				table[p] = i;
			}else{
				FLG = true;
				start = table[p];
				end = i-1;
				break;
			}
		}

		printf("\n");
		if(FLG){
			for(int i=0; i < start; i++)printf(" ");
			for(int i=start; i <= end; i++)printf("^");
			printf("\n");
		}

	}

    return 0;
}