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