标签:names ret return def print mes include 数组 string
给你一个数组,求所有的 $ a_i + a_j $ 的异或值。
因为 $ (a_i+a_j) \bigoplus (a_j + a_i) = 0$ 。
所以答案就是 $ \sum_{i=1}^n(2*a_i) $
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL ans,n,m,l,z,pre,T;
int main() {
scanf("%lld",&T);
while(T--) {
scanf("%lld%lld%lld%lld",&n,&m,&z,&l);
pre = 0 ,ans = 0;
for(int i = 1 ; i <= n ; i++) {
ans ^= pre * 2LL;
pre = (pre * m + z) % l;
}
printf("%lld\n",ans);
}
return 0;
}
标签:names ret return def print mes include 数组 string
原文地址:https://www.cnblogs.com/Repulser/p/11437400.html