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.
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).
The only line of output should contain a single integer — the value of Q.
3 1 2 3
3
1--n mod 1--n
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
long long esum[1000005];
int main()
{
int n;
while(~scanf("%d",&n))
{
long long ans=0;
for(int i=0;i<n;i++)
{
long long tp;
scanf("%lld",&tp);
ans^=tp;
}
esum[0]=0;
esum[1]=1;
for(int i=2;i<=n;i++)
{
esum[i]=i^esum[i-1];
}
for(int i=2;i<=n;i++)
{
int num=n/i;
int res=n%i;
if(num%2==1)
ans^=esum[i-1];
ans^=esum[res];
}
printf("%lld\n",ans);
}
}
本文介绍了一种特殊的计算方法,称为“魔法公式”,它使用位运算和模运算来处理一系列正整数,并最终计算出一个综合值Q。文章提供了具体的输入输出示例以及实现该计算任务的C++代码。
17万+

被折叠的 条评论
为什么被折叠?



