• MZL's xor


    MZL's xor

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
    Total Submission(s) : 1   Accepted Submission(s) : 1
    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 ($A_i$+$A_j$)($1leq i,j leq n$)
    The xor of an array B is defined as $B_1$ xor $B_2$...xor $B_n$
     
    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$ $A_1=0$,$A_i=(A_{i-1}*m+z)$ $mod$ $l$ $1leq m,z,l leq 5*10^5$,$n=5*10^5$
     
    Output
    For every test.print the answer.
     
    Sample Input
    2 3 5 5 7 6 8 8 9
     
    Sample Output
    14 16
     题解:就是A数组可以得出,B数组是A[i]+A[j]组成的数组让求B1^B2^.......^Bn的值;
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 const int MAXN=5*1e5+10;
     4 long long A[MAXN],B[MAXN];
     5 int main(){
     6     int T,n,m,z,l;
     7     scanf("%d",&T);
     8     while(T--){
     9         scanf("%d%d%d%d",&n,&m,&z,&l);
    10         A[0]=0;
    11         long long ans=0;
    12         for(int i=1;i<n;i++){
    13             A[i]=(A[i-1]%l*m%l+z%l)%l;
    14             B[i]=A[i]+A[i];//因为相同的元素异或结果为0;所以A[i]+A[j] | A[j]+A[i]等于0;只剩相同元素之和的异或; 
    15             ans^=B[i];
    16         }
    17         printf("%lld
    ",ans);
    18     }
    19     return 0;
    20 }
  • 相关阅读:
    ###第五次作业###
    第四次作业
    第三次作业
    jquery cookie插件
    jquery.form.js(ajax表单提交)
    jquery 中 $.map 用法
    jQuery中的$.grep()使用
    jquery-validation验证插件
    软件工程实践2017第一次作业
    jQuery UI dialog 的使用
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4872648.html
Copyright © 2020-2023  润新知