#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define reps(i,b,n) for(int i = b ; i < (int)n ; ++i )
#define rep(i,n) reps(i,0,n)
#define fr first
#define sc second
map<int,int> used;
int solve(int a,int b,int now){
  int r = a % b;
  if(used[r] != 0){
    cout << ( a / b ) << endl;
    used[r]-- , now++ ;
    rep(i,used[r]) cout << ' ';
    reps(i,used[r],now) cout << '^';
    cout << endl;
  }else{
    used[r] = now + 2;
    cout << ( a / b );
    if(r != 0) solve(r*10,b,now+1);
    else cout << endl;
  }
}
int main(){
  int p,q;
  cin >> p >> q;
  used[p%q] = 1;
  solve(p*10,q,0);
}