Uva--993(贪心)
2014-07-25 15:22:24
思路:简单贪心,从9开始一直考虑到2,即可。
1 /************************************************************************* 2 > File Name: h.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Fri 25 Jul 2014 03:09:32 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 16 int main(){ 17 int Case,n,res; 18 scanf("%d",&Case); 19 while(Case--){ 20 scanf("%d",&n); 21 if(n == 1) res = 1; 22 else res = 0; 23 for(int i = 9; i >= 2; --i){ 24 while(n > 1 && n % i == 0){ 25 n /= i; 26 res = res * 10 + i; 27 } 28 } 29 if(n == 1){ 30 int tres = 0; 31 while(res){ 32 tres = tres * 10 + res % 10; 33 res /= 10; 34 } 35 printf("%d\n",tres); 36 } 37 else 38 printf("-1\n"); 39 } 40 return 0; 41 }