Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int maxN = 18;
- int64_t fact[maxN];
- vector<int64_t> f;
- vector<int64_t> rand_suf;
- void pre_compute () {
- fact[0] = 1;
- for (int64_t i = 1; i < maxN; ++i) fact[i] = fact[i - 1] * i;
- for (int i = 1; i < maxN; ++i) f.push_back(fact[i]),rand_suf.push_back(fact[i]);
- }
- int64_t get_rand() {
- unsigned seed = rand() % 100 + rand() % 100 + 1;
- int64_t sum = 0;
- shuffle(rand_suf.begin(), rand_suf.end(), default_random_engine(seed));
- int n = rand() % maxN + 1;
- for (int i = 0; i < n; ++i) sum += rand_suf[i];
- return sum;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- pre_compute();
- int T = 1;
- //~ cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- int64_t n = get_rand();
- cout << n << '\n';
- int k = (int) f.size();
- for (int mask = 0; mask < (1 << k); ++mask) {
- vector<int64_t> bit;
- for (int i = 0; i < k; ++i) {
- if (mask & (1 << i)) bit.push_back(i);
- }
- int64_t sum = 0;
- for (int i = 0; i < (int) bit.size(); ++i) sum += f[bit[i]];
- if (sum == n) {
- cout << "YES\n";
- for (int i = 0; i < (int) bit.size(); ++i) cout << bit[i] + 1 << ' ';
- return 0;
- }
- }
- cout << "NO\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement