zoukankan      html  css  js  c++  java
  • 取余

    题目网址: 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;
    }
  • 相关阅读:
    练习四十:数组逆向输出
    练习三十九:数组插入排序
    Java awt组件间的继承关系
    java ArrayList
    java Scanner中的hasNext()方法
    java中String对象的存储位置
    java初始化块执行顺序
    java二维数组
    java数组变量
    Java数组初始
  • 原文地址:https://www.cnblogs.com/chen9510/p/5049505.html
Copyright © 2011-2022 走看看