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;
    }
  • 相关阅读:
    9th week
    8th Week 2
    8th Week 1
    课后作业-阅读任务-阅读提问-4
    2017-11-30-构建之法:现代软件工程-阅读笔记
    《团队-OldNote-项目总结》
    个人编程作业2-课程总结
    《团队-Oldnote-最终程序》
    课后作业-阅读任务-阅读提问-3
    《20171102-构建之法:现代软件工程-阅读笔记》
  • 原文地址:https://www.cnblogs.com/chen9510/p/5049505.html
Copyright © 2011-2022 走看看