Codeforces 424 C Magic Formulas
来源:互联网 发布:js修改classname 编辑:程序博客网 时间:2024/05/22 06:35
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:
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
31 2 3
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
- Codeforces 424 C Magic Formulas
- CodeForces 424C Magic Formulas
- codeforces 424C Magic Formulas
- Codeforces 424C Magic Formulas
- Codeforces 424C Magic Formulas(异或应用)
- codeforces 424C. Magic Formulas (异或规律)
- CF 424C Magic Formulas
- CF 424C Magic Formulas
- CodeForce 424C Magic Formulas
- Codeforce 424C Magic Formulas 找规律
- CodeForce 424C Magic Formulas(数学题)
- Codeforces Round #242 (Div. 2) C. Magic Formulas
- Codeforecs 424C Magic Formulas 规律+前缀和
- Codeforces Round242 div1A&div2C Magic Formulas
- Codeforces Round #242 (Div. 2) C: Magic Formulas 神奇的异或算式
- Magic Formulas
- CF 243 C. Magic Formulas(位运算)
- TOJ3582图书馆查询系统
- 最近服务器apache有问题,整的头都大了,好在解决了,记录下
- 2013年总结及2014年计划(初级程序员)
- hdu2049 不容易系列之(4)——考新郎
- xml文件的序列化 →创建xml文件
- Codeforces 424 C Magic Formulas
- 重拾CSDN博客,开启新的征途!
- Objective-C之run loop详解
- [Leetcode] Count and Say
- UVa437 The Tower of Babylon
- poj 1861 Network
- C++之练习题21
- 利用C++在vs2010配置OpenCV2.4.9
- 本体