Please help me optimize this solution

#include
#include
#include

using namespace std;

int main()
{
int n,t,i,j,k;
long res;
cin >> t;
while(t>=1)
{
cin >> n;
vector A(n,0);
vector B(n*n,0);
for(i=0;i<n;i++)
{
cin >> A[i];
}
k=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
B[k] = A[i] + A[j];
k++;
}
}
res = B[0];
for(i=0;i<k-1;i++)
{
res = (B[i+1]^res);
// cout << B[i] <<endl;
}
//cout << B[i] <<endl;
cout << res << endl;
t–;
}
return 0;
}

link to the problem

i know a very simple and straightr forward solution is present for this question but please help me optimize this particular solution

Since every integer appearing twice,
the Xor of ith element of B array would simply be,
Xor^=(2*Ai)

Print Xor