HDU题目链接

Problem Description

MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1i,jn)
The xor of an array B is defined as B1 xor B2…xor Bn

Input

Multiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
Each test case contains four integers:n,m,z,l
A1=0,Ai=(Ai1m+z) mod l
1m,z,l5105,n=5105

Output

#include <cstdio>
#include <set>
#include <algorithm>
#include <iterator>
#include <iostream>
using namespace std;
typedef long long ll;

const int maxn = 500000;
ll aa[maxn+10];

int main() {
ll T; cin >> T;
while(T--) {
ll n, m, z, l;
cin >> n >> m >> z >> l;
for(int i = 2; i <= n; ++i) {
aa[i] = (aa[i-1] * m + z) % l;
}
ll res = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
res ^= (aa[i]+aa[j]);
cout << res << endl;
}
return 0;
}


#include <cstdio>
#include <set>
#include <algorithm>
#include <iterator>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;

const int maxn = 500010;
ll  aa[maxn];
int main()
{
int T;
cin >> T;
while(T--)
{
ll n, m, z, l;
aa[1] = 0;
cin >> n >> m >> z >> l;
for(int i = 2; i <= n; ++i)
{
aa[i] = (aa[i-1] * m + z) % l;
}
ll res = 0;
for(int i = 1; i <= n; ++i)
res ^= (aa[i]+aa[i]);
cout << res << endl;
}
return 0;
}