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

 

posted @ 2014-04-28 22:14  null1019  阅读(84)  评论(0编辑  收藏  举报