首页 > 代码库 > Codeforces 424 C Magic Formulas

Codeforces 424 C Magic Formulas

Time Limit:2000MS     Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

SubmitStatus Practice CodeForces 424C

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 p1,p2, ...,pn. Lets write down some magic formulas:

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

The expression means applying the bitwisexor (excluding "OR") operation to integersx 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 sequencep, calculate the value of Q.

Input

The first line of the input contains the only integer n (1?≤?n?≤?106). The next line containsn 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
31 2 3
Output
3

题意:如题。

思路:纵向分析,先是p1^……^pn。。。不说了,贴个网址,我觉得说的肯定比我清楚。http://www.tuicool.com/articles/InYrm2M

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdlib.h>

using namespace std;

int p;
int a[1000006];

int main(){
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&p);
        ans^=p;
    }
    for(int i=1;i<=n;i++){
        a[i]=a[i-1]^i;
        if(n%(2*i)!=0){
            int x=n%(2*i);
            if(x>=i){
                ans^=a[i-1];
                x-=i;
            }
            ans^=a[x];
        }
    }
    printf("%d\n",ans);
    return 0;
}