Uva 10190 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int n, m;

    while(cin >> n >> m)
    {
        if(m == 0 || m == 1)
        {
            cout << "Boring!" << endl;
            continue;
        }
        int i = 0, f = 0, j;
        int a[250] = {0};
        while(n > 1)
        {
            if(n%m != 0)
            {
                f = 1;
                break;
            }
            else
            {
                if(i == 0)
                    a[i++] = n;
                n = n/m;
                a[i++] = n;
                f = 2;
            }
        }
        if(f == 1 || f == 0)
        {
            cout << "Boring!" << endl;
        }
        else
        {
            for(j=0;j<i;j++)
            {
                cout << a[j];
                if(j != i-1)
                    cout << " ";
            }
            cout << endl;
        }
    }

    return 0;
}

Comments