#35686:


ncsis19940123@gmail.com (楊博鈞)

學校 : 不指定學校
編號 : 235548
來源 : [114.41.219.230]
最後登入時間 :
2023-06-11 22:50:48
d418. 00993 - Product of digits -- UVa993 | From: [114.41.219.230] | 發表日期 : 2023-06-11 22:27

#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int T, N;
    cin >> T;
    while (T--) {
        cin >> N;
        if (N == 1) {
            cout << "1\n";
            continue;
        }
        int digit[10] = {0};
        for (int i=9; i>1; i--) {
            while (N % i == 0) {
                digit[i]++;
                N /= i;
            }
            if (N == 1) break;
        }
        if (N == 1) {
            long long ans = 0;
            for (int i=2; i<=9; i++) {
                while (digit[i]--) {
                    ans = ans * 10;
                    ans += i;
                }
            }
            cout << ans <<'\n';
        } else {
            cout << "-1\n";
        }
    }
    return 0;
}
 
ZeroJudge Forum