HDU 5344

来源:互联网 发布:caffe识别验证码 编辑:程序博客网 时间:2024/06/04 00:36

MZL's xor

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


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...xorBn
 

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)modl
1m,z,l5105,n=5105
 

Output
For every test.print the answer.
 

Sample Input
23 5 5 76 8 8 9
 

Sample Output
1416
 

Source
2015 Multi-University Training Contest 5



可以发现,a[i]+a[j]和a[j]+a[i]是相同的,异或值为0,所以真正有贡献的就是两倍的本身。
#include<iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>using namespace std;#define N 500005typedef long long ll;ll a[N],b[N];int len;int main(){    int i,j,n,m,t;    scanf("%d",&t);    while(t--)    {        len=0;        int z,l;        scanf("%d%d%d%d",&n,&m,&z,&l);        a[1]=0;        for(i=2; i<=n; i++)            a[i]=(a[i-1]*m+z)%l;        int sum=a[1];        /*        for(i=1;i<=n;i++)        for(j=1;j<=n;j++)        {            b[len++]=a[i]+a[j];        }        for(i=1;i<len;i++)        {            b[i]=b[i-1]^b[i];        }        cout<<b[len-1]<<endl;        */        for(i=2; i<=n; i++)        {            a[i]=a[i-1]^a[i];        }        printf("%lld\n",a[n]*2);    }}

 
 
0 0