#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a,b,c,d;
int ans[10000000];
int flg[10000000];
int main(){
  for(int i=0;i<=10000000;i++)flg[i]=-1;
  while(cin>>n>>m){
    for(int i=0;i<=d;i++)flg[i]=-1;
    
    n=n%m;
    d=c=-1;
    for(int i=0;i<=10000000;i++){
      n*=10;
      if(flg[n]!=-1){
	c=i;break;
      }
      flg[n]=i;d=max(d,n);
      ans[i]=n/m;
      cout<<ans[i];
      n=n%m;
      if(n==0)break;
    }
    cout<<endl;
    if(c!=-1){
      for(int i=1;i<=c;i++){
	if(i<=flg[n]){
	  cout<<' ';
	}else{
	  cout<<'^';
	}
      }
    cout<<endl;
    }
  }
  return 0;
}