Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code : XOR World

#include <bits/stdc++.h>
using namespace std;

long long f(long long n) {
    int rem = n % 4;

    // All elements inside the box.
    if (rem == 3) {
        return 0;
    }
    // One extra element outside the box.
    if (rem == 0) {
        return n;
    }
    // One element missing to complete the box.
    if (rem == 2) {
        return n + 1;
    }
    // 2 elements outside the box.
    if (rem == 1) {
        return 1;
    }

    return -1;
}

void solve() {
    long long A, B;
    cin >> A >> B;
    auto res = f(B) ^ (A ? f(A - 1) : 0);
    cout << res << "\n";
}

int main() {
    solve();
    return 0;
}