Pagini recente » tema | tema | Istoria paginii runda/rar91/clasament | Cod sursa (job #489937) | Cod sursa (job #3296707)
#include <fstream>
#include <iostream>
using namespace std;
int n, a[1000001], b[1000001], c[1000001], t[1000001], rez[1000001];
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
int findd(int i)
{
if(t[i] == 0)
return i;
return t[i] = findd(t[i]);
}
int unionn(int x, int y)
{
if(x != y)
t[x] = y;
}
int main()
{
fin >> n >> a[1] >> b[1] >> c[1];
if(a[1] > b[1])
swap(a[1], b[1]);
for(int i = 2; i < n; i++)
{
a[i] = 1LL*(a[i-1]*i)%n;
b[i] = 1LL*(b[i-1]*i)%n;
c[i] = 1LL*(c[i-1]*i)%n;
if(a[i] > b[i])
swap(a[i], b[i]);
}
for(int i = n-1; i >= 1; i--)
{
int x = findd(a[i]), y = findd(b[i]+1);
cout << x << " " << y << "\n";
while(x <= b[i])
{
rez[x] = c[i];
unionn(x, b[i]+1);
x = findd(x+1);
}
}
for(int i = 1; i <= n-1; i++)
fout << rez[i] << "\n";
return 0;
}