#P9223. 「PEOI Rd1」异或(xor)

「PEOI Rd1」异或(xor)

Problem Description

Given two positive integers n,mn, m, compute:

$$\sum_{i=1}^{n}\sum_{j=1}^{m}\left(i \oplus j\right)$$

Here, \oplus denotes the bitwise XOR operation (i.e., the ^ operator in C++). Output the answer modulo 998244353998244353.

Input Format

This problem contains multiple test cases.

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

The next TT lines each contain two integers n,mn, m.

Output Format

Output TT 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 n,mn, m \leq Special Property Points
11 10310^3 None 1010
22 10610^6 2020
33 101610^{16} A
44 None 5050
  • Special Property A: It is guaranteed that n=2p1n = 2^p - 1 and m=2q1m = 2^q - 1, where p,qZp, q \in \mathbb Z.

For 100%100\% of the testdata, it is guaranteed that 1n,m10161 \leq n, m \leq 10^{16} and 1T501 \leq T \leq 50.

Translated by ChatGPT 5