#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>

using namespace std;

void Solution()
{
    int a, b;
    
    while(cin>>a>>b)
    {
        map<int, int> used;
        
        vector<int> ans;
        
        int n = a * 10;
        
        bool flag = true;
        
        int start;
        int size;
        
        size = 0;
        
        used[a] = size++;
        
        for(;;)
        {
            ans.push_back(n / b);
            
            int m = n % b;
            
            if(m == 0)
            {
                break;
            }
            
            if(used.count(m)) // check if "m" is including array
            {
                flag = false;
                start = used[m];
                break;
            }
            
            used[m] = size++;
            
            n %= b;
            n *= 10;
        }
        
        for(int i = 0; i < ans.size(); i++)
        {
            cout << ans[i];
        }
        
        cout << endl;
        
        if(flag)
        {
            continue;
        }
        
        for(int i = 0; i < ans.size(); i++)
        {
            if(i < start)
            {
                cout << " ";
            }
            else
            {
                cout << "^";
            }
        }
        
        cout << endl;
    }
}

int main()
{
    Solution();
    return 0;
}