Advertisement
anon20016

F

Nov 14th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. long long binpow(long long a, int n, long long p) {
  13. long long res = 1;
  14. while (n > 0) {
  15. if (n & 1)
  16. res = (res * a) % p;
  17. a = (a * a) % p;
  18. n >>= 1;
  19. }
  20. return res;
  21. }
  22.  
  23. int main() {
  24. freopen("input.txt", "r", stdin);
  25. freopen("output.txt", "w", stdout);
  26. multiset<long long> a;
  27. long long n, p, b;
  28. scanf("%lld %lld %lld", &n, &b, &p);
  29. for (int i = 0; i < n; i++) {
  30. a.insert(binpow(b, i + 1, p));
  31. }
  32. for (int i = 0; i < n - 1; i++) {
  33. long long q = *a.begin();
  34. long long w = *a.rbegin();
  35. a.erase(a.find(q));
  36. a.erase(a.find(w));
  37. printf("%lld ", (q + w) % p);
  38. a.insert((q + w) % p);
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement