Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<string> perm;
- void F (string s = "",int n = 17) {
- if ((int) s.size() == n) {
- perm.push_back(s);
- return;
- }
- string x = s;
- string y = s;
- x.push_back('0');
- y.push_back('1');
- F(x,n);
- F(y,n);
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //~ cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- F();
- vector<long long> f;
- f.push_back(1LL);
- for (int i = 2; i <= 17; ++i) {
- f.push_back(f.back() * i);
- }
- long long n;
- cin >> n;
- for (int i = 0; i < (int) perm.size(); ++i) {
- string s = perm[i];
- long long sum = 0;
- for (int j = 0; j < (int) s.size(); ++j) {
- if (s[j] == '1') {
- sum += f[j];
- }
- }
- if (sum == n) {
- for (int j = 0; j < (int) s.size(); ++j) {
- if (s[j] == '1') cout << j + 1 << ' ';
- }
- return 0;
- }
- }
- cout << -1 << '\n';
- }
- //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement