#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int memo[1000*1000+1];

int main(){
  int p,q;
  while(~scanf("%d%d",&p,&q)){
    int cnt = 0;
    memset(memo,-1,sizeof(memo));
    while((p != 0) && (memo[p] == -1)){
      memo[p] = cnt++;
      p *= 10;
      int tmp = p/q;
      printf("%d",tmp);
      p -= q*tmp;
    }
    puts("");
    if(p == 0) continue;
    REP(i,cnt){
      if(i >= memo[p])
	putchar('^');
      else
	putchar(' ');
    }
    puts("");
  }
  return 0;
}