Miyago147852

UVa 993

Nov 18th, 2021
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. #define IO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  4. #define MAXN maxn
  5. #define MOD modn
  6. #define ll unsigned long long
  7.  
  8. using namespace std;
  9.  
  10. string solve(int a) {
  11.     string res = "";
  12.     if (a == 1) return "1";
  13.     for (int i=9; i>1; i--) {
  14.         while (!(a%i)) {
  15.             res = char(i+48) + res;
  16.             a /= i;
  17.         }
  18.     }
  19.     return (a!=1?"-1":res);
  20. }
  21.  
  22. signed main(){
  23.     IO;
  24.     //freopen("p.in", "r", stdin);
  25.     //freopen("p.out", "w", stdout);
  26.     int T, n; cin>>T;
  27.     while (T--) {
  28.         cin>>n;
  29.         cout<<solve(n)<<endl;
  30.     }
  31.     return EXIT_SUCCESS;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment