2015 Multi-University Training Contest-5 MZL's xor

来源:互联网 发布:饥荒 知乎 编辑:程序博客网 时间:2024/06/01 08:46

2015 Multi-University Training 

Contest-5 

MZL's xor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 688    Accepted Submission(s): 440

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)(1≤i,j≤n)
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=(Ai−1∗m+z) mod l
1≤m,z,l≤5∗105,n=5∗105

 

 

Output

For every test.print the answer.

 

 

Sample Input

23 5 5 76 8 8 9

 

 

Sample Output

1416

分析:

问题的关键在ij的取值上, (Ai+Aj)(1i,jn)   仔细阅读只要发现ij的取值范围,只要在1~n之间都符合,并没有强调ij需要满足某种关系,那么,凡是i=j的情况,都会导致( Ai+Aj )( Aj+Ai )想与产生零的情况,而其他任何数和零相与都不变,所以可以无视i=j的所有情况,只需要计算所有的i==j的情况,并且全部相与即可得出答案。

 

 

 

#include<iostream>using namespace std;__int64 a[500005];int main(){    int t;    cin >> t;    while (t--)    {        int n, m, z, l, s = 0;        cin >> n >> m >> z >> l;        a[1] = 0;        for (int i = 2; i <= n; i++)        {            a[i] =( (a[i - 1] * m) % l + z%l)%l;            <span style="font-family: Arial, Helvetica, sans-serif;">s ^= a[i] + a[i];</span>
        }        cout << s << endl;    }    return 0;}


0 0