All Tracks Basic Programming Bit Manipulation Basics of Bit Manipulation Problem

The Castle Gate
Tag(s):

Bit manipulation, Very-Easy

Problem
Editorial
Analytics

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$$

SAMPLE INPUT
3
4
6
8
SAMPLE OUTPUT
3
12
21
Explanation

For N=4, pairs are (1,2) , (1,3) and (2,3)

Time Limit: 2.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

July Easy '16

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications