Pagini recente » Cod sursa (job #2543054) | Cod sursa (job #2475721)
//#include "pch.h"
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
class OutParser {
private:
static const int buffSZ = (1 << 15);
ofstream File;
char buff[buffSZ];
int buffPos;
vector <int> digits;
void _advance() {
if (++buffPos == buffSZ) {
File.write(buff, buffSZ);
buffPos = 0;
}
}
void printChar(char no) {
buff[buffPos] = no;
_advance();
}
public:
OutParser(const char *FileName) {
File.open(FileName);
digits.resize(11);
buffPos = 0;
}
~OutParser() {
File.write(buff, buffPos);
buffPos = 0;
}
OutParser& operator <<(char ch) {
printChar(ch);
return *this;
}
OutParser& operator <<(int no) {
int idx = 0;
if (no == 0)
digits[++idx] = 0;
while (no) {
digits[++idx] = no % 10;
no /= 10;
}
for (; idx; --idx)
printChar(digits[idx] + '0');
return *this;
}
};
ifstream fin("curcubeu.in");
OutParser fout("curcubeu.out");
int main() {
int n, A1, B1, C1;
fin >> n >> A1 >> B1 >> C1;
vector <int> A(n), B(n), C(n), nxt(n), ans(n);
A[1] = A1;
B[1] = B1;
C[1] = C1;
for (int idx = 2; idx < n; ++idx) {
A[idx] = (1LL * A[idx - 1] * idx) % n;
B[idx] = (1LL * B[idx - 1] * idx) % n;
C[idx] = (1LL * C[idx - 1] * idx) % n;
}
for (int idx = n - 1; idx >= 1; --idx) {
int st, dr;
if (A[idx] < B[idx])
st = A[idx], dr = B[idx];
else st = B[idx], dr = A[idx];
nxt[idx] = dr;
for(int id = st; id <= dr; ++id)
if (ans[id] == 0)
ans[id] = idx;
else id = nxt[ans[id]];
}
for (int idx = 1; idx < n; ++idx)
fout << C[ans[idx]] << '\n';
}