#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int md[1111111];
int main(void){
  int p,q;
  while(cin >> p >> q){
    memset(md,-1,sizeof(md));
    int n,m=-1;
    for(n = 0; p%q; n++){
      if(md[p%q]!=-1){
	m = md[p%q];
	break;
      }
      else md[p%q] = n;
      p = (p%q) * 10;
      cout << p/q;
    }
    cout << endl;
    if(m != -1){
      for(int i = 0; i < n; i++){
	cout << (i<m?' ':'^');
      }
      cout << endl;
    }
  }
}