HDU 5344 多校赛1002 MZL's xor
2015-08-04 16:11
393 查看
[align=left]Problem Description[/align]
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
[align=left]Input[/align]
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
[align=left]Output[/align]
For every test.print the answer.
[align=left]Sample Input[/align]
2
3 5 5 7
6 8 8 9
[align=left]Sample Output[/align]
14
16
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
[align=left]Input[/align]
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
[align=left]Output[/align]
For every test.print the answer.
[align=left]Sample Input[/align]
2
3 5 5 7
6 8 8 9
[align=left]Sample Output[/align]
14
16
#include <iostream> using namespace std; long long a[500001]; int main() { int T; long long n,m,z,l; while(cin>>T) { while(T--) { cin>>n>>m>>z>>l; a[1] = 0; for(int i=2;i<=n;i++) { a[i] = (a[i-1] * m + z) % l; } int sum = a[1]; for(int i=2;i<=n;i++) { sum ^= a[i]*2; } cout<<sum<<endl; } } return 0; }
相关文章推荐
- POJ 3264 Balanced Lineup RMQ问题 ST算法 O(1)查找区间最值
- 二叉树非递归遍历
- POJ 3620--Avoid The Lakes【DFS】
- Android SDK Mirror
- Spring知识点小结
- leetcode——Count Complete Tree Nodes
- Http基础(记忆笔记)
- 高效算法——B 抄书 copying books,uva714
- BaseAdapter的使用步骤以及setTag和getTag的作用
- windows安卓NDK编程
- Yslow-23条规则
- HBase分享系列(2)--写入细节
- Hibernate 学习笔记
- R语言饼图的绘制
- Android4.4深入浅出之SurfaceFlinger总体结构
- js前台分页显示后端JAVA数据响应
- 区间覆盖问题 SDUT2074
- uva 1613 Keep the Customer Satisfied
- GUI编程,单选按钮、复选框、消息框、消息响应函数的使用
- webdriver查找元素的几种方法