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

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值