#5108. Masked Popcount

0

Masked Popcount

Masked Popcount

题目描述

Given integers NN and MM, compute the sum ∑k=0N\displaystyle \sum_{k=0}^{N} popcount\rm{popcount}(k&M)(k \mathbin{\&} M), modulo 998244353998244353. Here, &\mathbin{\&} represents the bitwise AND\rm{AND} operation.

What is the bitwise $\rm{AND}$ operation? The result $x = a \mathbin{\&} b$ of the bitwise $\rm{AND}$ operation between non-negative integers $a$ and $b$ is defined as follows:

xx is the unique non-negative integer that satisfies the following conditions for all non-negative integers kk:

If the 2k2^k place in the binary representation of aa and the 2k2^k place in the binary representation of bb are both 11, then the 2k2^k place in the binary representation of xx is 11. Otherwise, the 2k2^k place in the binary representation of xx is 00.

For example, 3=11(2)3=11_{(2)} and 5=101(2)5=101_{(2)}, so 3&5=13 \mathbin{\&} 5 = 1.

What is $\rm{popcount}$? $\rm{popcount}$$(x)$ represents the number of $1$s in the binary representation of $x$.
For example, $13=1101_{(2)}$, so $\rm{popcount}$$(13) = 3$.

输入格式

The input is given from Standard Input in the following format: NN MM

输出格式

Print the answer as an integer.

4 3
4
0 0
0
1152921504606846975 1152921504606846975
499791890

提示

NN is an integer between 00 and 260−12^{60} - 1, inclusive. MM is an integer between 00 and 260−12^{60} - 1, inclusive.popcount\rm{popcount}(0&3)=0(0\mathbin{\&}3) = 0 popcount\rm{popcount}(1&3)=1(1\mathbin{\&}3) = 1 popcount\rm{popcount}(2&3)=1(2\mathbin{\&}3) = 1 popcount\rm{popcount}(3&3)=2(3\mathbin{\&}3) = 2 popcount\rm{popcount}(4&3)=0(4\mathbin{\&}3) = 0

The sum of these values is 44.
It is possible that N=0N = 0 or M=0M = 0.
Remember to compute the result modulo 998244353998244353.

标签: AtCoder|abc356D

来源

AtCoder|abc356D