#P9223. 「PEOI Rd1」异或(xor)
「PEOI Rd1」异或(xor)
Problem Description
Given two positive integers , compute:
$$\sum_{i=1}^{n}\sum_{j=1}^{m}\left(i \oplus j\right)$$Here, denotes the bitwise XOR operation (i.e., the ^ operator in C++). Output the answer modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer , the number of test cases.
The next lines each contain two integers .
Output Format
Output lines, each containing one integer, the answer for the corresponding test case.
2
2 2
3 3
6
12
2
4 8
8 9
144
420
Hint
Sample Explanation
For the first sample test case:
$\begin{aligned}&(1 \oplus 1)+(1 \oplus 2)+(2 \oplus 1)+(2 \oplus 2)\\=\ &0+3+3+0\\=\ &6\end{aligned}$
For the second sample test case:
$\begin{aligned}&(1 \oplus 1)+(1 \oplus 2)+(1 \oplus 3)+(2 \oplus 1)+(2 \oplus 2)+(2 \oplus 3)+(3 \oplus 1)+(3 \oplus 2)+(3 \oplus 3)\\=\ &0+3+2+3+0+1+2+1+0\\=\ &12\end{aligned}$
Constraints
| Subtask | Special Property | Points | |
|---|---|---|---|
| None | |||
| A | |||
| None |
- Special Property A: It is guaranteed that and , where .
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5