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

MZL's xor

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


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 ...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=(Ai1m+z)   mod   l
1m,z,l5105 , n=5105
 


 

Output

 

For every test.print the answer.
 


 

Sample Input

 

  
  
2 3 5 5 7 6 8 8 9
 


 

Sample Output

 

  
  
14 16
 


 

Source

 


题意:给你n、m、z、l,定义A1=0,根据公式求出A1到An,然后定义Bi+j = Ai+Aj ,这里需要你看清楚一点,就是那个提示:(1 <= i , j <= n)那么就应该是排列而不是组合,

A1+A2和A2+A1分别对应的是B12和B21,然后就是异或的一个特性:异或同一个数偶数次,然并卵~~~所有的 i != j构成的 Bij 和 Bji 数值上是相同的,都异或起来不就是

然并卵了?剩下的就只要把 i == j的异或起来就行了。

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
#define LL long long
using namespace std;
int main()
{
    LL t,n,m,i,j,k,l,z,sum;
    scanf("%lld",&t);
    while(t--&&scanf("%lld%lld%lld%lld",&n,&m,&z,&l))
    {
        sum=0;
        j=k=0;
        for(i=2;i<=n;i++)
        {
            k=(j*m+z)%l;//求出Ai
            j=k;
            sum^=2*k;//异或Bii
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值