#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int xorOperation(int n, int start) {
int res = 0;
for(int i = 0; i < n; i ++)
res ^= start + 2 * i;
return res;
}
};
int main() {
cout << Solution().xorOperation(3, 2) << endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int xorOperation(int n, int start) {
return 2 * f(n, start / 2) + ((start % 2 == 0 || n % 2 == 0) ? 0 : 1);
}
private:
int f(int n, int start){
if(start % 2 == 0)
return n % 2 ? ((n / 2) & 1) ^ (start + n - 1) : ((n / 2) & 1);
return f(n + 1, start - 1) ^ (start - 1);
}
};
int main() {
cout << Solution().xorOperation(3, 2) << endl;
return 0;
}