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;
    }
  • 相关阅读:
    用内联取代宏代码
    参数的缺省值
    令人迷惑的隐藏规则
    重载与覆盖
    重载是如何实现的?
    重载的起源
    C++函数的高级特性
    使用调试器逐步跟踪程序
    new/delete 的使用要点
    malloc/free 的使用要点
  • 原文地址:https://www.cnblogs.com/chen9510/p/5049505.html
Copyright © 2011-2022 走看看