#P8766. [蓝桥杯 2021 国 AB] 异或三角

[蓝桥杯 2021 国 AB] 异或三角

Problem Description

Given TT numbers n1,n2,,nTn_{1}, n_{2}, \cdots, n_{T}, for each nin_{i}, find how many triples a,b,ca, b, c satisfy:

  1. 1a,b,cni1 \leq a, b, c \leq n_{i};

  2. abc=0a \oplus b \oplus c = 0, where \oplus denotes bitwise XOR in binary;

  3. The three sides with lengths a,b,ca, b, c can form a triangle.

Input Format

The first line contains an integer TT.

The next TT lines each contain an integer, representing n1,n2,,nTn_{1}, n_{2}, \cdots, n_{T}.

Output Format

Output TT lines, each containing an integer, representing the corresponding answer.

2
6
114514
6
11223848130

Hint

For 10%10\% of the testdata, T=1T = 1, 1ni2001 \leq n_{i} \leq 200.

For 20%20\% of the testdata, T=1T = 1, 1ni20001 \leq n_{i} \leq 2000.

For 50%50\% of the testdata, T=1T = 1, 1ni2201 \leq n_{i} \leq 2^{20}.

For 60%60\% of the testdata, 1T1000001 \leq T \leq 100000, 1ni2201 \leq n_{i} \leq 2^{20}.

For all testdata, 1T1000001 \leq T \leq 100000, 1ni2301 \leq n_{i} \leq 2^{30}.

Lanqiao Cup 2021 National Contest, Group A Problem I (Group B Problem J).

Translated by ChatGPT 5