Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include <iostream> #include <vector> using namespace std; int main() { int t,c; long long int n; vector<long long int> v; cin>>t; while(t--) { cin>>n; if(n<=9) { cout<<n<<"\n"; continue; } while(n>=10) { v.clear(); c=0; for(long long int i=9;i>=2;i--) { if(n%i==0) { c=1; n/=i; v.push_back(i); break; } } if(n<10) { v.push_back(n); break; } if(c==0) { v.clear(); cout<<"-1\n"; break; } } if(v.size()==0) continue; for(int i=v.size()-1;i>=0;i--) cout<<v[i]; cout<<"\n"; } return 0; } |