Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- int main()
- {
- //good random number generator
- mt19937 rng(time(0));
- int n, p, x;
- cin >> n >> p >> x;
- vector<int> a(n);
- for (auto& it : a) cin >> it;
- if (x == 1) return 0;
- while (true)
- {
- //shuffles the array
- shuffle(begin(a), end(a), rng);
- int cur = 1;
- for (int i = 0; i < n; ++i)
- {
- cur = 1ll * cur * a[i] % p;
- if (cur == x)
- {
- for (int j = 0; j <= i; ++j)
- cout << a[j] << " ";
- return 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment