#include #ifdef WIN32 #define getchar_fast _getchar_nolock #else #define getchar_fast getchar_unlocked #endif int ri() { int c, r = 0, s = 0; while (1) { c = getchar(); if (c == '-') { s = 1; break; } if (c >= '0' && c <= '9') { r = c - '0'; break; } } while (1) { c = getchar(); if (c < '0' || c > '9') break; r = r * 10 + c - '0'; } return s ? -r : r; } void out(long long n) { printf("%lld\n", n); } int main() { int m = ri(); int n = ri(); int mulx = ri(); int addx = ri(); int muly = ri(); int addy = ri(); int mod = ri(); int mask = mod - 1; std::vector cnt(mod); { std::vector x(m); for (int i = 0; i < m; i++) x[i] = ri(); int prev_x = x.back(), prev_y; for (int i = 0; i < m; i++) { int y = prev_y = ri(); cnt[x[i]] += y; } for (int i = m; i < n; i++) { int new_x = ((int64_t) prev_x * mulx + addx) & mask; int new_y = ((int64_t) prev_y * muly + addy) & mask; cnt[new_x] += new_y; prev_x = new_x; prev_y = new_y; } } std::vector table(mod, true); for (int i = 2; i < mod; i++) if (table[i]) { for (int j = i * 2; j < mod; j += i) table[j] = false; int max = (mod - 1) / i; for (int j = max; j; j--) cnt[j] += cnt[j * i]; } int64_t xored = 0; int prev_a, prev_b; { std::vector a(m); for (int i = 0; i < m; i++) a[i] = ri(); for (int i = 0; i < m; i++) { int b = prev_b = ri(); int64_t res = cnt[a[i]]; if ((int64_t) a[i] * b < mod) res -= cnt[a[i] * b]; xored ^= res; out(res); } prev_a = a.back(); } for (int i = m; i < n; i++) { int new_a = (((int64_t) prev_a * mulx + addx + mod - 1) & mask) + 1; int new_b = (((int64_t) prev_b * muly + addy + mod - 1) & mask) + 1; int64_t res = cnt[new_a]; if ((int64_t) new_a * new_b < mod) res -= cnt[new_a * new_b]; xored ^= res; prev_a = new_a; prev_b = new_b; } out(xored); return 0; }