Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "CAU3"
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- constexpr int N = 4e5 + 5;
- int t, m(0), id[15];
- string s[15], res[N];
- void Read()
- {
- cin >> t;
- }
- // Tương đương hàm to_string
- string Get(int v)
- {
- string ans;
- while (v > 0)
- {
- ans.push_back(char(v % 10 + '0'));
- v /= 10;
- }
- reverse(ans.begin(), ans.end());
- return ans;
- }
- void Solve()
- {
- // Phân tích nguyên tố
- for (int i = 2; i * i <= t; ++i)
- {
- string tmp = Get(i);
- if (t % i == 0)
- {
- ++m;
- while (t % i == 0)
- {
- t /= i;
- // Do các số giống nhau nằm liền nhau
- s[m] += tmp;
- }
- }
- }
- // Nếu t có ước nguyên tố lớn hơn căn t
- if (t != 1)
- {
- ++m;
- s[m] = Get(t);
- }
- // Duyệt hoán vị
- for (int i = 1; i <= m; ++i)
- id[i] = i;
- string ans;
- do
- {
- string tmp;
- for (int i = 1; i <= m; ++i)
- tmp += s[id[i]];
- ans = max(ans, tmp);
- } while (next_permutation(id + 1, id + m + 1));
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Add Comment
Please, Sign In to add comment