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;
    }
  • 相关阅读:
    Linux命令——find
    Linux命令——locate
    python模块:datetime
    python模块:json
    python模块:shelve
    python模块:shutil
    python模块:sys
    python:OS模块
    str.index()与str.find()比较
    python模块:re
  • 原文地址:https://www.cnblogs.com/chen9510/p/5049505.html
Copyright © 2011-2022 走看看