Hdu 5344

Hdu5344

题意:

给你一个数组,求所有的 $ a_i + a_j $ 的异或值。

解法:

因为 $ (a_i+a_j) igoplus (a_j + a_i) = 0$ 。
所以答案就是 $ sum_{i=1}^n(2*a_i) $

CODE:

#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
",ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Repulser/p/11437400.html