码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5344(2015多校5)-MZL's xor(水题)

时间:2015-08-05 10:31:17      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:xor

题目地址:HDU 5344
题意:求所有(Ai+Aj)的异或值。
思路:可以发现(Ai+Aj)和(Aj+Ai)的异或值为0,所以最后只剩下(Ai+Ai)。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
LL n,m,z,l,ans;
LL a[500010];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        memset(a,0,sizeof(a));
        scanf("%lld %lld %lld %lld",&n,&m,&z,&l);
        a[1]=0;
        ans=0;
        for(int i=2;i<=n;i++){
            a[i]=(a[i-1]*m+z)%l;
            ans^=(a[i]*2);
        }
        printf("%d\n",ans);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5344(2015多校5)-MZL's xor(水题)

标签:xor

原文地址:http://blog.csdn.net/u013486414/article/details/47292751

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!