Advertisement
newb_ie

Untitled

Sep 7th, 2021
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxN = 18;
  5. int64_t fact[maxN];
  6. vector<int64_t> f;
  7. vector<int64_t> rand_suf;
  8.  
  9. void pre_compute () {
  10. fact[0] = 1;
  11. for (int64_t i = 1; i < maxN; ++i) fact[i] = fact[i - 1] * i;
  12. for (int i = 1; i < maxN; ++i) f.push_back(fact[i]),rand_suf.push_back(fact[i]);
  13. }
  14.  
  15. int64_t get_rand() {
  16. unsigned seed = rand() % 100 + rand() % 100 + 1;
  17. int64_t sum = 0;
  18. shuffle(rand_suf.begin(), rand_suf.end(), default_random_engine(seed));
  19. int n = rand() % maxN + 1;
  20. for (int i = 0; i < n; ++i) sum += rand_suf[i];
  21. return sum;
  22. }
  23.  
  24. int main () {
  25. ios::sync_with_stdio(false);
  26. cin.tie(nullptr);
  27. cout.tie(nullptr);
  28. pre_compute();
  29. int T = 1;
  30. //~ cin >> T;
  31. for (int test_case = 1; test_case <= T; ++test_case) {
  32. int64_t n = get_rand();
  33. cout << n << '\n';
  34. int k = (int) f.size();
  35. for (int mask = 0; mask < (1 << k); ++mask) {
  36. vector<int64_t> bit;
  37. for (int i = 0; i < k; ++i) {
  38. if (mask & (1 << i)) bit.push_back(i);
  39. }
  40. int64_t sum = 0;
  41. for (int i = 0; i < (int) bit.size(); ++i) sum += f[bit[i]];
  42. if (sum == n) {
  43. cout << "YES\n";
  44. for (int i = 0; i < (int) bit.size(); ++i) cout << bit[i] + 1 << ' ';
  45. return 0;
  46. }
  47. }
  48. cout << "NO\n";
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement