Advertisement
Gosunov

Untitled

Aug 10th, 2023
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(a) (a).begin(), (a).end()
  4.  
  5. void solve() {
  6.     int n;
  7.     cin >> n;
  8.     if (n == 1) {
  9.         cout << 1 << '\n';
  10.         return;
  11.     }
  12.     vector<int> a;
  13.     int cnt2 = 0;
  14.     int cnt3 = 0;
  15.     while (n % 2 == 0) {
  16.         n /= 2;
  17.         cnt2++;
  18.     }
  19.     while (n % 3 == 0) {
  20.         n /= 3;
  21.         cnt3++;
  22.     }
  23.     for (int i = 5; i * i <= n; ++i) {
  24.         while (n % i == 0) {
  25.             n /= i;
  26.             a.push_back(i);
  27.         }
  28.     }
  29.     if (n != 1)
  30.         a.push_back(n);
  31.     for (int i : a) {
  32.         if (i >= 10) {
  33.             cout << "Invalid series" << '\n';
  34.             return;
  35.         }
  36.     }
  37.     for (int i = 0; i < cnt2 / 3; ++i) {
  38.         a.push_back(8);
  39.     }
  40.     for (int i = 0; i < cnt3 / 2; ++i) {
  41.         a.push_back(9);
  42.     }
  43.     cnt2 %= 3;
  44.     cnt3 %= 2;
  45.     if (cnt2 == 0 && cnt3 == 0) {
  46.         // no
  47.     } else if (cnt2 == 1 && cnt3 == 0) {
  48.         a.push_back(2);
  49.     } else if (cnt2 == 2 && cnt3 == 0) {
  50.         a.push_back(4);
  51.     } else if (cnt2 == 0 && cnt3 == 1) {
  52.         a.push_back(3);
  53.     } else if (cnt2 == 1 && cnt3 == 1) {
  54.         a.push_back(6);
  55.     } else if (cnt2 == 2 && cnt3 == 1) {
  56.         a.push_back(2);
  57.         a.push_back(6);
  58.     } else { assert(false); }
  59.     sort(all(a));
  60.     for (int i : a) {
  61.         cout << i;
  62.     }
  63.     cout << '\n';
  64. }
  65.  
  66. signed main() {
  67.     ios::sync_with_stdio(0); cin.tie(0);
  68.     solve();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement