The Castle Gate
Practice
3.6 (163 votes)
Bit manipulation
Easy
Ready
Problem
83% Success 15327 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Gudi, a fun loving girl from the city of Dun, travels to Azkahar - a strange land beyond the mountains. She 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.
The gates of the castle are closed. An integer N is engraved on the gates. A writing on the wall says

Tap 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.


Help her find the number of the times she has to tap.

Input:
First line contains an integer T, T testcases follow.
Each testcase consists of an integer N.

Output:
Print the answer to each testcase in a newline.

Constraints:
\( 1 \le T \le 100\)
\( 2 \le N \le 2000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
80 votes
Tags:
Bit manipulationBit ManipulationBasics of Bit ManipulationBasic Programming
Points:10
8 votes
Tags:
ImplementationBasics of Bit ManipulationBasic ProgrammingBit ManipulationBit manipulation
Points:10
46 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulation