CodeForce 424C Magic Formulas
这个题就是求出给的公式的结果。
仅仅要知道异或运算满足交换律跟结合律即可了。之后就是化简公式。
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
int psum[1000010];
int main()
{
int n;
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
{
int t;
scanf("%d",&t);
ans^=t;
}
for(int i=1;i<n;i++)
psum[i]=i^psum[i-1];
for(int i=1;i<=n;i++)
{
int t=n/i;
if(t&1)
ans^=psum[i-1];
t=n%i;
ans^=psum[t];
}
cout<<ans;
}
2 seconds
256 megabytes
standard input
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.
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).
The only line of output should contain a single integer — the value of Q.
3
1 2 3
3
CodeForce 424C Magic Formulas的更多相关文章
- Codeforce 424C Magic Formulas 找规律
题目链接:http://codeforces.com/contest/424/problem/C 题意:求Q值 思路:找规律 显然能够得到一个矩阵 把这个矩阵画出来就能发现一个横向的规律和一个主对角线 ...
- Codeforces 424 C. Magic Formulas
xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律 C. Magic Formulas ...
- codeforce-424C. Magic Formulas(数学)
C. Magic Formulas time limit per test:2 seconds memory limit per test:256 megabytes input stan ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas
解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)
题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1. 交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...
- codeforce 606A - Magic Spheres
题意:a,b,c三种球,能把俩个一样的球变成另一颜色不一样的球.给你目标x,y,z,问能否经过变化至少达打目标. #include<iostream> #include<stdio. ...
- cf C. Magic Formulas
http://codeforces.com/contest/424/problem/C #include <cstdio> #include <cstring> #includ ...
- codeforces C. Magic Formulas 解题报告
题目链接:http://codeforces.com/problemset/problem/424/C 题目意思:给出 n 个数:p1, p2, ..., pn,定义: q1 = p1 ^ (1 mo ...
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
随机推荐
- 紫书 习题 10-15 UVa 12063(数位dp)
大佬真的强!!https://blog.csdn.net/u014800748/article/details/45225881 #include<cstdio> #include< ...
- Hadoop学习总结(1)——大数据以及Hadoop相关概念介绍
一.大数据的基本概念 1.1.什么是大数据 大数据指的就是要处理的数据是TB级别以上的数据.大数据是以TB级别起步的.在计算机当中,存放到硬盘上面的文件都会占用一定的存储空间,例如: 文件占用的存储空 ...
- ArcGIS api for javascript——地图配置-定制导航箭头
描述 本例展示了如何为平移地图包括自定义的按钮.地图被放置在一个宽3列和高3行的HTML表格的固定宽度中心单元.表格里剩余的单元放置标签为8个主要方向的缩写的按钮.每个按钮调用地图上不同的平移函数.例 ...
- easyui combobox 取值
easyui combobox 取值 var zhudaoci = $.trim($('#spanZhudaociId').combobox('getValue')); 学习了:http://blog ...
- Yocto tips (10): Yocto hellworld 加入一个软件包
Yocto中一个软件包是放在bb文件里的,然后非常多的bb文件集成一个recipe(配方),然后很多的recipe又组成一个meta layer.因此,要加入一个包事实上就是在recipe以下加入一个 ...
- linux内核计算时间差以及jiffies溢出
jiffies是每一个时钟中断,都会加1.这就导致一个问题.不管jiffies(一般来说是unsigned long类型)多少个字节,总有溢出的时候. 更极端的时候.当期jiffies是0xfffff ...
- caioj1442:第k小的数Ⅱ
[传送门:caioj1442] 简要题意: 给出n个点,每个点都有一个权值,m个操作,操作有两种:第一种是询问l到r的第k小的值,然后输出这个值,第二种是将第x个点的值改为k 题解: 又是一道主席树的 ...
- RequestMapping、Responsebody、RequestBody
预备知识:@RequestMappingRequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径.@RequestM ...
- Spring security工作流程及集成
A user enters their username and password into a login screen and clicks a login button. The entered ...
- 局域网ARP病毒的清理
局域网ARP病毒的清理 作者:IT动力源 来源:IT动力源收集整理 现在局域网中感染ARP 病毒的情况比较多,清理和防范都比较困难,给不少的网络管理员造成了很多的困扰.下面就是个人在处理这个 ...