Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define all(a) (a).begin(), (a).end()
- void solve() {
- int n;
- cin >> n;
- if (n == 1) {
- cout << 1 << '\n';
- return;
- }
- vector<int> a;
- int cnt2 = 0;
- int cnt3 = 0;
- while (n % 2 == 0) {
- n /= 2;
- cnt2++;
- }
- while (n % 3 == 0) {
- n /= 3;
- cnt3++;
- }
- for (int i = 5; i * i <= n; ++i) {
- while (n % i == 0) {
- n /= i;
- a.push_back(i);
- }
- }
- if (n != 1)
- a.push_back(n);
- for (int i : a) {
- if (i >= 10) {
- cout << "Invalid series" << '\n';
- return;
- }
- }
- for (int i = 0; i < cnt2 / 3; ++i) {
- a.push_back(8);
- }
- for (int i = 0; i < cnt3 / 2; ++i) {
- a.push_back(9);
- }
- cnt2 %= 3;
- cnt3 %= 2;
- if (cnt2 == 0 && cnt3 == 0) {
- // no
- } else if (cnt2 == 1 && cnt3 == 0) {
- a.push_back(2);
- } else if (cnt2 == 2 && cnt3 == 0) {
- a.push_back(4);
- } else if (cnt2 == 0 && cnt3 == 1) {
- a.push_back(3);
- } else if (cnt2 == 1 && cnt3 == 1) {
- a.push_back(6);
- } else if (cnt2 == 2 && cnt3 == 1) {
- a.push_back(2);
- a.push_back(6);
- } else { assert(false); }
- sort(all(a));
- for (int i : a) {
- cout << i;
- }
- cout << '\n';
- }
- signed main() {
- ios::sync_with_stdio(0); cin.tie(0);
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement