Uva 993 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, m, j, i;
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> m;
        if(m<10)
        {
            cout << m << endl;
            continue;
        }
        j = 9;
        vector<int>p;
        while(j>1 && m>1)
        {
            while(m%j == 0)
            {
                m = m/j;
                p.push_back(j);
            }
            j--;
        }
        sort(p.begin(), p.end());
        if(m == 1)
        {
            for(j=0;j<p.size();j++)
                cout << p[j];
            cout << endl;
        }
        else
            cout << -1 << endl;
    }
    return 0;
}

Comments