码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 424 C Magic Formulas

时间:2014-07-28 00:08:19      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   java   os   strong   io   for   

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

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:

bubuko.com,布布扣
bubuko.com,布布扣

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

The expression bubuko.com,布布扣 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

题意:如题。

思路:纵向分析,先是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;
}





Codeforces 424 C Magic Formulas,布布扣,bubuko.com

Codeforces 424 C Magic Formulas

标签:des   style   http   java   os   strong   io   for   

原文地址:http://blog.csdn.net/kimi_r_17/article/details/38172781

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!