There is no. need of any matrix …it is just simple logic…i dont know why they used gaussian elemination like stuff…here is my code simple logic.Please explain the editorial in the most simplest way so that the users can understand and not fear the editorial
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define whatis(x) cout << #x << " is " << x << endl;
//initialization of variable
int numone[20];
ull totalsum;
ull xorsum[20];
int n;
void solve() {
for (int i = 0; i < 20; i++) {
ull k = (1 << i);
ull tempsum = (totalsum + xorsum[i]);
tempsum = tempsum - (n * k);
tempsum = tempsum / 2;
ull currentbitsum = totalsum - tempsum;
currentbitsum = currentbitsum / k;
numone[i] = currentbitsum;
}
}
//Initializer function
void init() {
memset(numone, 0, sizeof(numone));
memset(xorsum, 0, sizeof(xorsum));
totalsum = 0;
n = 0;
}
//Query function
void query() {
ull q = (1 << 20);
cout << 1 << " " << q << endl;
cin >> totalsum;
totalsum = totalsum - (ull)(n*q);
for (int i = 1; i < 20; i++) {
q = (1 << i);
cout << 1 << " " << q << endl;
cin >> xorsum[i];
if (xorsum[i] == (-1)) {
exit(0);
}
cout.flush();
}
}`Preformatted text`
//Function to print the ans
void ans() {
ull ans = 0;
for (int i = 19; i > 0; i--) {
if (numone[i] % 2 != 0) {
ans = ans + (ull)(1 << i);
}
}
totalsum = totalsum - ans;
if(totalsum%2!=0){
ans+=1;
}
cout << 2 << " " << ans << endl;
cout.flush();
int res;
cin >> res;
if (res == (-1)) {
exit(0);
}
}
int main() {
ll test;
cin >> test;
while (test--) {
init();
cin >> n;
//Initialization
//Query for all the bits
query();
//Solve for the number of bits
solve();
//ans the sum
ans();
}
}