define _CRT_SECURE_NO_WARNI NGS include iostream include cstdio includ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <iomanip>
#define ll long long
#define eps 1e-8
#define all(x) x.begin(), x.end()
#define Cout cout << fixed << setprecision(6)
using namespace std;
unsigned int F[100000] = { 0 };
unsigned int G[100000] = { 0 };
unsigned int H[100000] = { 0 };
unsigned int cur = 0;
unsigned int a, b;
vector<vector<pair<int, int> > > g(100006);
void generate_masks(int n) {
for (int i = 0; i < (1 << n); ++i) {
for (int i1 = 0; i1 <= i; ++i1) {
for (int i2 = 0; i2 <= i; ++i2) {
if ((i1 | i2) == i) {
g[i].push_back(make_pair(i1, i2));
}
}
}
}
}
unsigned int nextRand16() {
cur = cur * a + b;
return cur / (1 << 16);
}
int main(){
#ifndef _DEBUG
freopen("convolution.in", "r", stdin);
freopen("convolution.out", "w", stdout);
#endif
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
#endif
unsigned int n, t;
cin >> n >> t >> a >> b;
generate_masks(n);
while (t--){
for (int i = 0; i < (1 << n); ++i)
H[i] = 0;
for (int i = 0; i < (1 << n); ++i)
F[i] = nextRand16();
for (int i = 0; i < (1 << n); ++i)
G[i] = nextRand16();
for (int i = 0; i < (1 << n); ++i) {
unsigned int k = 0;
for (int q = 0; q < g[i].size(); ++q) {
H[i] = H[i] + F[g[i][q].first] * G[g[i][q].second];
/*overflows here*/
}
}
ll ans = 0;
for (int i = 0; i < (1 << n); ++i) {
ans += H[i] * (i + 1);
}
ans %= (1ll << 32);
cout << ans << endl;
}
return 0;
}