Pagini recente » Borderou de evaluare (job #3326323) | summer_camp_2 | Monitorul de evaluare | Cod sursa (job #1863590) | Cod sursa (job #3353461)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int a, b, c, n, v[N];
int parent[N];
int find_parent(int node) {
if (parent[node] == node) return node;
return parent[node] = find_parent(parent[node]);
}
void unite(int x, int y) {
parent[x] = y;
}
long long exp(long long e, int pow) {
long long ans = 1;
for (long long bit = 1; bit <= pow; bit <<= 1) {
if (bit & pow) {
ans = (ans * e) % n;
}
e = (e * e) % n;
}
return ans;
}
int main() {
freopen("curcubeu.in", "r", stdin);
freopen("curcubeu.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b >> c;
for (int i = 1; i <= n; ++i) parent[i] = i;
for (int i = 2; i < n; ++i) {
a = 1LL * a * i % n;
b = 1LL * b * i % n;
c = 1LL * c * i % n;
}
for (int i = n - 1; i >= 1; --i) {
int l = min(a, b), r = max(a, b);
l = find_parent(l);
while (l <= r) {
v[l] = c;
unite(l, l + 1);
l = find_parent(l);
}
long long aux = exp(i, n - 2); // a/i%mod <=> a * i**(mod-2)%mod
a = 1LL * a * aux % n;
b = 1LL * b * aux % n;
c = 1LL * c * aux % n;
}
for (int i = 1; i < n; ++i) {
cout << v[i] << '\n';
}
return 0;
}