Guest User

Untitled

a guest
Jan 13th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. int main()
  4. {
  5. //good random number generator
  6. mt19937 rng(time(0));
  7.  
  8. int n, p, x;
  9. cin >> n >> p >> x;
  10. vector<int> a(n);
  11. for (auto& it : a) cin >> it;
  12.  
  13. if (x == 1) return 0;
  14.  
  15.  
  16. while (true)
  17. {
  18. //shuffles the array
  19. shuffle(begin(a), end(a), rng);
  20.  
  21. int cur = 1;
  22. for (int i = 0; i < n; ++i)
  23. {
  24. cur = 1ll * cur * a[i] % p;
  25. if (cur == x)
  26. {
  27. for (int j = 0; j <= i; ++j)
  28. cout << a[j] << " ";
  29. return 0;
  30. }
  31. }
  32. }
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment