Codeforces 424 C magic formulas

Source: Internet
Author: User

Time limit:2000 msMemory limit:262144kb64bit Io format:% I64d & % i64u

Submitstatus practice codeforces limit 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 numbersP1,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 IntegersXAndY. 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 valueQ.

Input

The first line of the input contains the only integerN(1? ≤?N? ≤? 106). The next line containsNIntegers:P1 ,?P2 ,?...,?PN(0? ≤?PI? ≤? 2 · 109 ).

Output

The only line of output shoshould contain a single integer-the valueQ.

Sample Input

Input
31 2 3
Output
3

Question: for example, question.

Train of Thought: Vertical analysis, first P1 ^ ...... ^ PN... If you don't talk about it, post a website. I think it is clearer than I do. Http://www.tuicool.com/articles/InYrm2M

AC code:

#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;}



Zookeeper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.