Advertisement
kdzhr

1014

Feb 16th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. // OK greedy Timus 1014 https://acm.timus.ru/problem.aspx?space=1&num=1014
  2.  
  3. # include <iostream>
  4. # include <vector>
  5. using namespace std;
  6.  
  7. int main() {
  8.     int32_t q;
  9.     cin >> q;
  10.     if (q == 1) {
  11.         cout << 1;
  12.         return 0;
  13.     }
  14.     if (q == 0) {
  15.         cout << 10;
  16.         return 0;
  17.     }
  18.     vector<int32_t> res(10, 0);
  19.     for (int32_t i = 9; i > 1 && q != 1; i--) {
  20.         while (q % i == 0) {
  21.             res[i]++;
  22.             q /= i;
  23.         }
  24.     }
  25.     if (q != 1) {
  26.         cout << -1;
  27.     }
  28.     else {
  29.         for (size_t i = 1; i < 10; i++) {
  30.             for (size_t j = 0; j < res[i]; j++) {
  31.                 cout << i;
  32.             }
  33.         }
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement