CF1815D.XOR Counting

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given two positive integers nn and mm. Find the sum of all possible values of a1⨁a2⨁…⨁ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m, where a1,a2,…,ama_1,a_2,\ldots,a_m are non-negative integers such that a1+a2+…+am=na_1+a_2+\ldots+a_m=n.

Note that all possible values a1⨁a2⨁…⨁ama_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 998244353998244353.

Here, ⨁\bigoplus denotes the bitwise XOR operation.

给定两个正整数 nn 和 mm。求所有可能的 a1⨁a2⨁…⨁ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m 的值之和,其中 a1,a2,…,ama_1,a_2,\ldots,a_m 为非负整数,且满足 a1+a2+…+am=na_1+a_2+\ldots+a_m=n。

注意:所有可能的值 a1⨁a2⨁…⨁ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m 在求和中仅计算一次(即去重后求和)。

由于答案可能过大,请将结果对 998244353998244353 取模后输出。

此处,⨁\bigoplus 表示按位异或运算(bitwise XOR)。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \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 nn and mm (0≤n≤1018,1≤m≤1050\le n\le 10^{18}, 1\le m\le 10^5) — the sum and the number of integers in the set, respectively.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 mm(0≤n≤1018,1≤m≤1050\le n\le 10^{18}, 1\le m\le 10^5),分别表示集合中所有整数的和以及集合中整数的个数。

输出格式

For each test case, output the sum of all possible values of a1⨁a2⨁…⨁ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m among all non-negative integers a1,a2,…,ama_1,a_2,\ldots,a_m with a1+a2+…+am=na_1+a_2+\ldots+a_m=n. As the answer may be too large, output your answer modulo 998244353998244353.

对于每组测试数据,输出所有满足 a1+a2+…+am=na_1+a_2+\ldots+a_m=n 的非负整数序列 a1,a2,…,ama_1,a_2,\ldots,a_m 对应的 a1⨁a2⨁…⨁ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m 的所有可能取值之和。由于答案可能过大,请将结果对 998244353998244353 取模后输出。

输入输出样例

  • 输入#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 a1=69a_1=69, so it's the only possible value of a1a_1, therefore our answer is 6969.

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

For the third test case, a1,a2,…,a10a_1,a_2,\ldots,a_{10} must be all 00, so a1⨁a2⨁…⨁a10=0a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_{10}=0. Therefore our answer is 00.

对于第一个测试用例,必须有 a1=69a_1=69,因此 a1a_1 的唯一可能取值为 6969,故答案为 6969。

对于第二个测试用例,(a1,a2)(a_1,a_2) 可以是 (0,5),(1,4),(2,3),(3,2),(4,1)(0,5), (1,4), (2,3), (3,2), (4,1) 或 (5,0)(5,0),对应地,a1⨁a2a_1\bigoplus a_2 的值分别为 5,5,1,1,5,55,5,1,1,5,5。因此 a1⨁a2a_1\bigoplus a_2 的可能取值为 11 或 55,故答案为 1+5=61+5=6。

对于第三个测试用例,a1,a2,…,a10a_1,a_2,\ldots,a_{10} 必须全为 00,因此 a1⨁a2⨁…⨁a10=0a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_{10}=0。故答案为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页