fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #define all(x) (x).begin(), (x).end()
  5. #define pb push_back
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8. typedef long long ll;
  9. template <typename T>
  10. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  11.  
  12.  
  13. void solve() {
  14. ll n;
  15. cin >> n;
  16. vector<ll> a(n);
  17. ll ans = 0;
  18.  
  19. for (ll i = 0; i < n; i++) {
  20. cin >> a[i];
  21. ans ^= a[i];
  22. }
  23. vector<ll> xorr(n + 1);
  24. xorr[0] = 0;
  25. for (ll i = 1; i <= n; i++) {
  26. xorr[i] = i ^ xorr[i - 1];
  27. }
  28.  
  29.  
  30. for (ll i = 1 ; i<= n; i++) {
  31. // ll diff = n-i ;
  32. //if (diff&1) ans^=i;
  33. ll nb=n/i , MOD = n%i;
  34. if (nb&1) ans^=xorr[i-1];
  35. ans^=xorr[MOD];
  36.  
  37. }
  38.  
  39.  
  40. cout << ans << endl;
  41. }
  42.  
  43. int main() {
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46. ll t = 1;
  47. //cin >> t;
  48.  
  49. while (t--) solve();
  50. return 0;
  51. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
247