-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagicFormulas.cpp
More file actions
51 lines (47 loc) · 889 Bytes
/
MagicFormulas.cpp
File metadata and controls
51 lines (47 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
AUTHOR: Antarikshya Mitra
TIME:
PROBLEM NO:- MAGIC FORMULAS 424C
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
void solve(vector<int> arr)
{
int n = arr.size();
int Q = 0;
for(int i=0;i<n;i++)
Q=Q^arr[i];
vector<int> prefix_XOR(n);
for(int i=0;i<n;i++)
{
prefix_XOR[i] = i; // 0 1 2 3 4
}
for(int i=1;i<n;i++)
prefix_XOR[i] = prefix_XOR[i-1] ^ prefix_XOR[i]; // 0 1 3 0 4 1 7 0
for(int i=2;i<=n;i++)
{
int segments = n/i;
if(segments%2==1)
Q = Q ^ prefix_XOR[i-1];
int remaining = n%i;
Q = Q ^ prefix_XOR[remaining];
}
cout<<Q<<endl;
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
vector<int> arr(n);
for (auto &a:arr)
cin>>a;
solve(arr);
return 0;
}