xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律

C. Magic Formulas
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
input
3
1 2 3

output
3

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>using namespace std;int XOR[1100000];int main()
{int ans=0,n;scanf("%d",&n);for(int i=0;i<n;i++){int p;scanf("%d",&p);ans^=p;}for(int i=1;i<=n-1;i++){XOR[i]=XOR[i-1]^i;int len=i+1;int res=n%(len*2);if(res>=len){ans^=XOR[i];res-=len;}ans^=XOR[res];}printf("%d\n",ans);return 0;
}

转载于:https://www.cnblogs.com/cxchanpin/p/6855510.html

Codeforces 424 C. Magic Formulas相关推荐

  1. Codeforces 424C Magic Formulas

    题目链接:[这里写链接内容] (http://codeforces.com/contest/424/problem/C) 题面: C. Magic Formulas(神奇的矩阵) time limit ...

  2. 【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

    题干: Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degene ...

  3. 【CodeForces - 670D1 】Magic Powder - 1 (模拟 或 枚举 或二分优化)

    题干: This problem is given in two versions that differ only by constraints. If you can solve this pro ...

  4. (最小生成树)Codeforces Educational Codeforces Round 9 Magic Matrix

    You're given a matrix A of size n × n. Let's call the matrix with nonnegative elements magic if it i ...

  5. Codeforces 711B- Chris and Magic Square

    B. Chris and Magic Square time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. codeforces_#242 (Div. 2)

    这个在codeforces的题目编号是424A-424E 424A,Squats 题目地址:http://codeforces.com/problemset/problem/424/A 题目意思: 就 ...

  7. the development of c language(转)

    c语言之父Dennis Ritchie 写的关于c语言开发历史的文章,来自这里 lisp专家Richard P.Gabriel 的<the Rise of Worse is Better > ...

  8. java 平均值_Java求两个数平均值

    如何正确的求2个数的平均值.在练习算法二分查找的时候发现的,以前没有注意到的bug 备注:数据以int类型为例 一.以前的通用写法 /** * 求a+b平均值 * @param a * @param ...

  9. 知乎上看到的一篇计算机发展史

    1822 年,Charles Babbage 研发差分机(自动化算术).英国政府赞助. 1832 年,差分机只能完成 1/7. 1837 年,Charles Babbage 研发出一个电脑, Mech ...

最新文章

  1. poj 2482 Stars in Your Window(线段树+离散化+线扫描)
  2. C语言结构体对齐的不足
  3. 【Linux】一步一步学Linux——id命令(94)
  4. struts+hibernate+oracle+easyui实现lazyout组件的简单案例——struts.xml配置详情
  5. leetcode之回溯backtracing专题4
  6. cognos的HTMl显示,cognos利用html项目和提示元素结合
  7. Java实现简单的银行管理系统(最基本的功能/易上手)
  8. IBM要推POWER9,来了解一下POWER处理器的前世今生
  9. oo结尾的单词发音规律
  10. 2021-2025年中国共享Web托管服务行业市场供需与战略研究报告
  11. HDU 6045 Is Derek lying?
  12. mysql 1449 问题
  13. 彩色证件照片常用的红色、蓝色背景颜色值 1
  14. Rpm、Yum(程序包管理)
  15. 访问局域网计算机切换用户,图解“访问局域网中的电脑时提示输入帐号和密码”...
  16. CPU卡读写操作函数
  17. 在总账模块结账的时候提示总账和明细账对账不平结不了账
  18. java语言获取数据库中的表的总行数
  19. CGI跟FASTCGI区别
  20. pygame像素地图的实现

热门文章

  1. 看我如何利用Mac官方AppStore中的应用程序获取root权限
  2. 网站建设常用英文翻译对照
  3. 操作系统学习笔记(十四)~进程同步单元测试
  4. HIVE SQL tricks
  5. B站基于Iceberg的湖仓一体架构实践
  6. 走进语音识别中的WFST(四)
  7. 使用幕布怎么删除创建的节点?
  8. 2021年压力容器作业(R)移动式压力容器充装(R2)考试题库
  9. 【整理】【持续完善】物联网星座项目介绍
  10. 修改whmcs首页模板