Advertisement
newb_ie

Untitled

Sep 9th, 2021
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<string> perm;
  5. void F (string s = "",int n = 17) {
  6. if ((int) s.size() == n) {
  7. perm.push_back(s);
  8. return;
  9. }
  10. string x = s;
  11. string y = s;
  12. x.push_back('0');
  13. y.push_back('1');
  14. F(x,n);
  15. F(y,n);
  16. }
  17.  
  18. int main () {
  19. ios::sync_with_stdio(false);
  20. cin.tie(nullptr);
  21. cout.tie(nullptr);
  22. int T = 1;
  23. //~ cin >> T;
  24. for (int test_case = 1; test_case <= T; ++test_case) {
  25. F();
  26. vector<long long> f;
  27. f.push_back(1LL);
  28. for (int i = 2; i <= 17; ++i) {
  29. f.push_back(f.back() * i);
  30. }
  31. long long n;
  32. cin >> n;
  33. for (int i = 0; i < (int) perm.size(); ++i) {
  34. string s = perm[i];
  35. long long sum = 0;
  36. for (int j = 0; j < (int) s.size(); ++j) {
  37. if (s[j] == '1') {
  38. sum += f[j];
  39. }
  40. }
  41. if (sum == n) {
  42. for (int j = 0; j < (int) s.size(); ++j) {
  43. if (s[j] == '1') cout << j + 1 << ' ';
  44. }
  45. return 0;
  46. }
  47. }
  48. cout << -1 << '\n';
  49. }
  50. //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
  51. }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement