#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int vist[1000010];
int main(){
  int a,b;
  while(cin>>a>>b){
    a%=b;
    for(int i=0;i<1000010;i++)vist[i]=-1;
    int len=0;
    while(a){
      if(vist[a]==-1)vist[a]=len;
      else break;
      //cout<<"#"<<a<<" ";
      a*=10;
      int tmp=a/b;
      a%=b;
      //cout<<a<<" "<<vist[a]<<" "<<tmp<<endl;
      len++;
      cout<<tmp;
    }
    cout<<endl;
    if(vist[a]==-1)continue;
    for(int i=0;i<len;i++){
      if(i<vist[a])cout<<" ";
      else cout<<"^";
    }
    cout<<endl;
  }
  return 0;
}