Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- using namespace std;
- long long binpow(long long a, int n, long long p) {
- long long res = 1;
- while (n > 0) {
- if (n & 1)
- res = (res * a) % p;
- a = (a * a) % p;
- n >>= 1;
- }
- return res;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- multiset<long long> a;
- long long n, p, b;
- scanf("%lld %lld %lld", &n, &b, &p);
- for (int i = 0; i < n; i++) {
- a.insert(binpow(b, i + 1, p));
- }
- for (int i = 0; i < n - 1; i++) {
- long long q = *a.begin();
- long long w = *a.rbegin();
- a.erase(a.find(q));
- a.erase(a.find(w));
- printf("%lld ", (q + w) % p);
- a.insert((q + w) % p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement