cf C. Magic Formulas

http://codeforces.com/contest/424/problem/C

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define maxn 1000001
 6 using namespace std;
 7 
 8 int f[maxn],n;
 9 long long  a[maxn];
10 void inti()
11 {
12     f[0]=0;
13     f[1]=1;
14     for(int i=2; i<=maxn; i++)
15     {
16         f[i]=f[i-1]^i;
17     }
18 }
19 int main()
20 {
21     inti();
22     scanf("%d",&n);
23     cin>>a[0];
24     long long sum=a[0];
25     for(int i=1; i<n; i++)
26     {
27         cin>>a[i];
28         sum^=a[i];
29     }
30     for(int i=0; i<n; i++)
31     {
32         if(i==0) sum^=0;
33         else
34         {
35             int m1=n%(i+1);
36             int m2=n/(i+1);
37             if(m2%2==0)
38             {
39                 if(m1==0)
40                 {
41                     if(i+1==n)
42                     {
43                         sum^=(f[i]^0);
44                     }
45                     else
46                     {
47                         sum^=0;
48                     }
49                 }
50                 else
51                 {
52                     sum^=f[m1];
53                 }
54             }
55             else
56             {
57                 int m3=f[i]^0;
58                 if(m1==0)
59                 {
60                     if(i+1==n)
61                     {
62                         sum^=(f[i]^0);
63                     }
64                     else
65                     {
66                         sum^=(f[i]^0);
67                     }
68                 }
69                 else
70                 {
71                     sum^=(f[m1]);
72                     sum^=(f[i]^0);
73                 }
74             }
75         }
76     }
77     cout<<sum<<endl;
78     return 0;
79 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3698069.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值