• 取余


    题目网址: http://codeforces.com/contest/424/problem/C

    Description

    People in the Tomskaya region like magic formulas very much. You can see some of them below.

    Imagine you are given a sequence of positive integer numbers p1p2, ..., pn. Lets write down some magic formulas:

    Here, "mod" means the operation of taking the residue after dividing.

    The expression  means applying the bitwise xor (excluding "OR") operation to integers x and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by "^", in Pascal — by "xor".

    People in the Tomskaya region like magic formulas very much, but they don't like to calculate them! Therefore you are given the sequence p, calculate the value of Q.

    Input

    The first line of the input contains the only integer n (1 ≤ n ≤ 106). The next line contains n integers: p1, p2, ..., pn (0 ≤ pi ≤ 2·109).

    Output

    The only line of output should contain a single integer — the value of Q.

    Sample Input

    Input
    3
    1 2 3
    Output
    3

    
    
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <cstdio>
    using namespace std;
    long long a[1000005];
    
    int main()
    {
        int i,n;
        long long p,sum;
        a[0]=0;
        for(i=1;i<=1000004;i++)
        a[i]=a[i-1]^i;
        while(cin>>n)
        {
           sum=0;
           for(i=0;i<n;i++)
           {
               scanf("%lld",&p);
               sum=sum^p;
           }
           for(i=2;i<=n;i++)
           {
               int c=n%i;
               int cc=n/i;
               if(cc&1)
               {
                   sum=sum^a[i-1];
               }
               sum=sum^a[c];
           }
            cout<<sum<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Sharding-JDBC(三)3.1.0版本实践
    Sharding-JDBC(二)2.0.3版本实践
    Sharding-JDBC(一)简介
    Java并发(六)线程池监控
    Java并发(五)线程池使用番外-分析RejectedExecutionException异常
    Java并发(四)线程池使用
    Java并发(三)线程池原理
    Java并发(二)异步转同步
    tarjan+概率
    线段树(种树)
  • 原文地址:https://www.cnblogs.com/chen9510/p/5049505.html
Copyright © 2020-2023  润新知