A15962 | XOR Counting
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
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](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
输入格式
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.
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.
输出格式
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$ .
输入输出样例
输入 #1
7 69 1 5 2 0 10 420 69 12 26 73 34 1000000000000000000 10
输出 #1
69 6 0 44310 42 1369 216734648
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted