#P6599. 「EZEC-2」异或

    ID: 5522 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学贪心进制位运算,按位构造

「EZEC-2」异或

Description

There are TT queries. In each query, you are given two positive integers n,ln, l.

You need to construct a positive integer sequence aa of length ll (indexed from 11 to ll), such that for all i[1,l]i \in [1, l], we have ai[1,n]a_i \in [1, n].

Find the maximum value of:

i=1lj=1i1aiaj\sum_{i=1}^l\sum_{j=1}^{i-1}a_i\oplus a_j

To avoid the answer being too large, for each query, you only need to output this maximum value modulo 109+710^9+7.

Input Format

The first line contains an integer TT, representing the number of test cases.

Then from line 22 to line T+1T+1, each line contains two integers n,ln, l, representing the maximum possible value of aia_i and the length of aa, respectively.

Output Format

Output TT lines, each containing one integer: the answer for the corresponding query modulo 109+710^9+7.

1
2 3

6
2
114 514
1919 180

8388223
16580700

Hint

Sample Explanation #1
When n=2,l=3n=2, l=3, if aa is any permutation of {1,2,1}\{1,2,1\}, the maximum value can be achieved, which is (12)+(11)+(21)=6(1\oplus2)+(1\oplus1)+(2\oplus1)=6. It is easy to prove that the expression reaches its maximum in this case.


Constraints | Test Point ID | TT\le | nn\le | ll\le | | :----------: | :----------: | :----------: | :----------: | | 151\sim5 | 11 | 1010 | 55 | | 66 | 5×1055\times 10^5 | 101210^{12} | 22 | | 77 | 5×1055\times 10^5 | 101210^{12} | 33 | | 8108\sim10 | 5×1055\times 10^5 | 101210^{12} | 10510^5 |

For 100%100\% of the data, 1T5×1051\le T\le 5\times10^5, 1n10121\le n\le 10^{12}, 2l1052\le l \le 10^5.


Hints

  1. "\oplus" is the bitwise XOR operator. If you do not know what bitwise XOR is, you can refer to here.
  2. Modulo is an operation. Taking aa modulo bb means assigning aa to the remainder when aa is divided by bb.
    In C++ / Python, the modulo operator is %, and in Pascal it is mod.
  3. \sum is the summation symbol. If you do not know what \sum means, you can refer to here.
  4. Please pay attention to the impact of input/output efficiency on your program.

Translated by ChatGPT 5