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 )(1≤i,j≤n )
The xor of an array B is defined asB1 xor B2 ...xorBn
The xor of an array B is defined as
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
Each test case contains four integers:
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
- HDU 5344
- HDU 5344
- HDU-5344
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- css编写超出元素宽度的中文显示省略号
- HDU 5347 MZL's chemistry
- c++实现链表的抽象数据结构
- POJ 3620 Avoid The Lakes(dfs)
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
- HDU 5344
- 剑指Offer面试题24(Java版):二叉搜索树的后序遍历序列
- Android复习笔记(10) -对话框的使用
- HDU 5351 MZL's Border
- HDU 2546 饭卡
- 多线程1
- UVa 567 Risk (Floyd+任意两点最短路)
- C语言编程入门——综合练习(三)学生管理系统
- 正则表达式30分钟入门教程