## The Castle Gate

QUESTION

Gudi, a fun loving girl from the city of Dun, travels to Azkahar – a strange land beyond the mountains. \n\nShe arrives at the gates of Castle Grey, owned by Puchi,the lord of Azkahar to claim the treasure that it guards. However, destiny has other plans for her as she has to move through floors, crossing obstacles on her way to reach the treasure.\n\nThe gates of the castle are closed. An integer N is engraved on the gates. A writing on the wall says\n\nTap the gates as many times as there are unordered pairs of distinct integers from 1 to N whose bit-wise XOR does not exceed N.\n\nHelp her find the number of the times she has to tap.\n\nInput:\n\nFirst line contains an integer T, T test cases follow.\nEach testcase consists of an integer N.\n\nOutput:\n\nPrint the answer to each test case in a newline.\n\nConstraints:\n\n1<=T<=100\n 2<=N<=2000.

``````#include <iostream>

int main()
{
int T; std::cin >> T;
for (int t_case = 0; t_case < T; ++t_case)
{
int N; std::cin >> N;
int count(0);
for (int x = 1; x < N; ++x)
for (int y = x + 1; y <= N; ++y)
if ((x ^ y) <= N)
++count;
std::cout << count << '\n';
}
return 0;
}``````