MZL's xor

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

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
2
3 5 5 7
6 8 8 9
 
Sample Output
14
16
 
Author
SXYZ
 
Source
AxorA=0 Axor0=A

i!=j时(Ai+Aj)xor(Ai+Aj)=0,剩下(A1+A1)xor(A2+A2)xor...xor(An+An),而Ai=(Ai−1∗m+z) mod l是产生随机数的函数,在一定长度下会出现循环,循环部分又可以约掉

 #include<cstdio>
#include<cstring>
bool b[];
int a[];
int main()
{
long long z, m, l;
int n, T;
scanf("%d", &T);
while (T--)
{
scanf("%d%lld%lld%lld", &n, &m, &z, &l);
int j, f, L, i;
memset(b, , sizeof(b));
L = ;
b[] = true;
a[] = ;
for (j = ;; j++)
{
L = (m*L + z) % l;//随机数产生函数,会有循环出现
if (b[L] == true) break;
b[L] = true;
a[j] = L;
}
int sum = ;
for (f = ; f < j; f++)
{
if (a[f] == L) break;
sum = sum ^ (a[f] << );
}
int cycle = j - f;
int div = (n - f) / cycle;
int mod = (n - f) % cycle;
if (div & )
{
for (i = f + mod; i < j; i++)
sum = sum ^ (a[i] << );
}
else
{
for (i = f; i < f + mod; i++)
sum = sum ^ (a[i] << );
}
printf("%d\n", sum);
}
}

hdu 5344 MZL's xor的更多相关文章

  1. hdu 5344 MZL's xor(数学之异或)

    Problem Description   MZL loves xor very much.Now he gets an array A.The length of A ≤i,j≤n) The xor ...

  2. HDU 5344 MZL's xor (多校)[补7月28]

    MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. HDU 5344 MZL's xor (水题)

    题意:给一个序列A,设序列B的中的元素有(Ai+Aj)(1≤i,j≤n),那么求B中所有元素的异或之和.而序列A是这样来的:A1=0,Ai=(Ai−1∗m+z) mod l. 思路:相同的元素异或结果 ...

  4. HDU 5344(MZL&#39;s xor-(ai+aj)的异或和)

    MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  5. hdoj 5344 MZL's xor

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5344 #include<stdio.h> #include<cstring> ...

  6. HDU 5351 MZL's Border (规律,大数)

    [HDU 5351 MZL's Border]题意 定义字符串$f_1=b,f_2=a,f_i=f_{i-1}f_{i-2}$. 对$f_n$的长度为$m$的前缀$s$, 求最大的$k$满足$s[1] ...

  7. hdu5344 MZL's xor(水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud MZL's xor Time Limit: 2000/1000 MS (Java/ ...

  8. MZL's xor

    MZL's xor Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Sub ...

  9. Hdu 5352 MZL's City (多重匹配)

    题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...

随机推荐

  1. 【转载】Recycle机制

    首先要明白,Recycle机制并不是Java中的垃圾回收机制,而是相当于一种设计模式 思想:当一个对象不再使用时,储存起来,而不是让虚拟机回收,需要的时候再用,避免对象被回收之后重分配 适用范围:对于 ...

  2. java 读取excel 正常 xls

    package com.sun.test; import java.io.BufferedInputStream;import java.io.File;import java.io.FileInpu ...

  3. 浙大 pat 1024题解

    1024. Palindromic Number (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  4. satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-usb-storage:

    卸载了包 : opkg remove kmod-ath9k - 3.10.49+2014-05-22-1 重新进行安装时出现如下错误: root@hbg:/tmp# opkg install /tmp ...

  5. Arch安装详解

    选择安装方式 CD/USB Arch启动盘安装 使用Arch启动盘比较简单方便,没有额外设置,直接阅读下一步. USB flash installation media 启动盘制作: USB flas ...

  6. ECOS 系统查找商品详情图片存入mysql情况。

    SELECT g.goods_id, g.bn,g.name,b.brand_name,g.price,g.mktprice,c.cat_name into outfile '/tmp/xxx.xls ...

  7. PIVOT就是行转列,UNPIVOT就是列传行

    PIVOT通过将表达式某一列中的唯一值转换为输出中的多个列来旋转表值表达式,并在必要时对最终输出中所需的任何其余列值执行聚合.UNPIVOT与PIVOT执行相反的操作,将表值表达式的列转换为列值. 通 ...

  8. ERROR 1406 : Data too long for column 解决办法

    解决办法: 在my.ini里找到 sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_Create_USER,NO_ENGINE_SUBSTITUTION” 把其中的STRIC ...

  9. STM32F207 两路ADC连续转换及GPIO模拟I2C给MT9V024初始化参数

    1.为了更好的方便调试,串口必须要有的,主要打印一些信息,当前时钟.转换后的电压值和I2C读出的数据. 2.通过GPIO 模拟I2C对镁光的MT9V024进行参数初始化.之前用我以前公司SP0A19芯 ...

  10. Python之路:爬虫之urllib库的基本使用和高级使用

    关于爬虫自己一直在看,所以时间太慢,这才第二更,有等不及的小伙伴可以慢慢的品尝了,在看下面的之前,建议先把上一章看一下.以下是关于python的Urllib的基础和高级用法. 1.如何扒下一个网站,用 ...