Codeforces 424C(异或)
来源:互联网 发布:舞蹈培训网络推广方案 编辑:程序博客网 时间:2024/05/16 14:34
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 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
3
1 2 3
3
Source
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;typedef long long LL;int a[1000005],b[1000005];int main(){ int i,j,t,len,n,s,ans; while(scanf("%d",&n)!=EOF) { scanf("%d",&t); ans=t; for(i=2;i<=n;i++) { scanf("%d",&t); ans^=t; } b[0]=0; for(i=1;i<=n;i++) { b[i]=b[i-1]^i; int tmp=n/i; if(tmp&1) ans^=b[i-1]; if(n%i) ans=ans^b[n%i]; } printf("%d\n",ans); } return 0;}
- Codeforces 424C(异或)
- Codeforces 424C Magic Formulas(异或应用)
- codeforces 424C. Magic Formulas (异或规律)
- CodeForces 288C--异或运算
- codeforces C—Short Program 与或异或运算
- codeforces:405C - Unusual Product 规律异或
- codeforces:405C - Unusual Product 规律异或
- CodeForces 501C Misha and Forest(异或和)
- Codeforces Round #242 (Div. 2) C: Magic Formulas 神奇的异或算式
- codeforces 405 C. Unusual Product and E. Graph Cutting (异或规律 & 搜索)
- Codeforces 501C:Misha and Forest(好题+思维+异或的运算规律+树)
- Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor(异或的性质)
- CodeForces 327C Magic Five 二分求和 或 矩阵求和
- Codeforces,578C,贪心出错,手工模拟“或”操作
- 【Codeforces 747 C Servers 】+ 思维 或 优先队列
- (数学或二分)Codeforces Round #426 C. The Meaningless Game
- codeforces 895C Square Subsets 线性基 或 状压DP
- C的|、||、&、&&、异或、~
- php多进程学习
- 辗转相除法的证明
- Codeforces 424A (思维题)
- CodeForces - 424B (贪心算法)
- 算法的重要性
- Codeforces 424C(异或)
- CodeForces - 426A(排序)
- CodeForces - 426B(对称图形)
- CodeForces - 427A (警察和罪犯 思维题)
- javascript 图片 懒加载、预加载
- CodeForces - 427B (模拟题)
- MyBatis之传入参数
- HDU 2.1.7 (求定积分公式)
- HDU2.2.3 (汉诺塔VII)