Codeforces Round 865 (Div. 1)
D
XOR Counting
Codeforces
2600
原题
← CE →
翻译中…

Given two positive integers $n$ and $m$. Find the sum of all possible values of $a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m$, where $a_1,a_2,\ldots,a_m$ are non-negative integers such that $a_1+a_2+\ldots+a_m=n$.

翻译中…

Note that all possible values $a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m$ should be counted in the sum exactly once.

翻译中…

As the answer may be too large, output your answer modulo $998244353$.

翻译中…

Here, $\bigoplus$ denotes the bitwise XOR operation.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of test cases follows.

翻译中…

The first and only line of each test case contains two integers $n$ and $m$ ($0\le n\le 10^{18}, 1\le m\le 10^5$) — the sum and the number of integers in the set, respectively.

翻译中…

Output

翻译中…

For each test case, output the sum of all possible values of $a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m$ among all non-negative integers $a_1,a_2,\ldots,a_m$ with $a_1+a_2+\ldots+a_m=n$. As the answer may be too large, output your answer modulo $998244353$.

翻译中…

Note

翻译中…

For the first test case, we must have $a_1=69$, so it's the only possible value of $a_1$, therefore our answer is $69$.

翻译中…

For the second test case, $(a_1,a_2)$ can be $(0,5), (1,4), (2,3), (3,2), (4,1)$ or $(5,0)$, in which $a_1\bigoplus a_2$ are $5,5,1,1,5,5$ respectively. So $a_1\bigoplus a_2$ can be $1$ or $5$, therefore our answer is $1+5=6$.

翻译中…

For the third test case, $a_1,a_2,\ldots,a_{10}$ must be all $0$, so $a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_{10}=0$. Therefore our answer is $0$.

翻译中…

样例

Input #1
7
69 1
5 2
0 10
420 69
12 26
73 34
1000000000000000000 10
Output #1
69
6
0
44310
42
1369
216734648
InputCopy OutputCopy
题目信息
题号
1815D
时间限制
2 s
内存限制
256 MB
标签
位运算
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。