Pagini recente » Cod sursa (job #881722) | Cod sursa (job #2452704)
#include <fstream>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int nmax = 1000000;
int n, A[nmax + 5], B[nmax + 5], C[nmax + 5], sol[nmax + 5], Nextt[nmax + 5];
int main()
{
fin >> n >> A[1] >> B[1] >> C[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;
}
for(int i = n - 1; i >= 1; i--)
{
int st = min(A[i], B[i]);
int dr = max(A[i], B[i]);
while(st <= dr)
{
if(Nextt[st] == 0)
{
sol[st] = C[i];
Nextt[st] = dr + 1;
st++;
}
else
st = Nextt[st];
}
}
for(int i = 1; i < n; ++i)
fout << sol[i] << "\n";
return 0;
}