Pagini recente » Cod sursa (job #2637021) | Cod sursa (job #2724724) | Cod sursa (job #2748565) | Cod sursa (job #2584627) | Cod sursa (job #2827734)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("xor3.in");
ofstream g("xor3.out");
const int maxn = 1005;
/*
void testMatrix() {
int a[maxn][maxn];
int n, i, j;
f >> n;
g << "0 ";
for(i = 1; i <= n; i ++) {
a[0][i] = i;
g << a[0][i] << ' ';
}
g << '\n';
for(i = 1; i <= n; i ++) {
g << "0 ";
for(j = 1; j <= n; j ++) {
a[i][j] = a[i-1][j] ^ a[i][j-1];
g << a[i][j] << ' ';
}
g << '\n';
}
}
*/
const int maxn = 1e6+5;
typedef long long lint;
lint q, x, y, a, b, m;
int lg[maxn];
void solve(lint x, lint y) {
/*
if(y % 2 == 0) {
x -= (x / y) * (y);
} else {
x -= (x / (y + 1)) * (y + 1);
}
*/
x -= (x / (1 << (lg[y] + 1))) * (1 << (lg[y] + 1));
}
int main()
{
for(i = 2; i <= maxn - 5; i ++) {
lg[i] = lg[i >> 1] + 1;
}
//testMatrix();
f >> q >> x >> y >> a >> b >> m;
while(q --) {
solve(x, y);
x = (a * x + b) % m;
y = (a * y + b) % m;
}
return 0;
}