UVA-993 - Product of Digits
16 Apr 2018題意概要
給你一個大於等於 的整數 ,請你你找到最小的自然數 ,使得在 中所有數字(digit)的乘積等於 。
- 分析:本題為簡單的貪婪法 (Greedy Method),如果 ,則可以直接回傳 即是答案,其他數字 () 從 開始遞減,只要可以整除 ,就加進答案內。
Input
The first line of input contains one positive integer number, which is the number of data sets. Each subsequent line contains one data set which consists of one non-negative integer number ().
Output
For each data set, write one line containing the corresponding natural number or -1
if does not exist.
Sample Input
3
1
10
123456789
Sample Output
1
25
-1