#pragma GCC optimize ("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #define FORCE_INLINE __attribute__((always_inline)) inline constexpr bool DEBUG = false; std::ifstream inF("power.in"); std::ofstream outF("power.out"); typedef unsigned int uint; uint a, b0, c, d; int n; void input() { inF >> a >> b0 >> c >> d >> n; } uint ans; void output() { outF << ans << "\n"; } constexpr int MAX_POWS = 1 << 16; uint aPowsLower[MAX_POWS]; uint aPowsHigher[MAX_POWS]; void solve() { aPowsLower[0] = 1; for (uint i = 1; i < 1 << 16; ++i) { aPowsLower[i] = aPowsLower[i - 1] * a; } uint a16 = aPowsLower[(1 << 16) - 1] * a; aPowsHigher[0] = 1; for (uint i = 1; i < 1 << 16; ++i) { aPowsHigher[i] = aPowsHigher[i - 1] * a16; } ans = 0; uint b = b0; for (int i = 0; i < n; ++i) { b = b * c + d; uint lower = b & (MAX_POWS - 1); uint higher = b >> 16; ans = ans ^ (aPowsHigher[higher] * aPowsLower[lower]); } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); input(); solve(); output(); return 0; }