#abc356d. D - Masked Popcount

D - Masked Popcount

Score : 400400 points

问题陈述

给定整数 NNMM,计算和 k=0N\displaystyle \sum_{k=0}^{N} popcount\rm{popcount}(k&M)(k \mathbin{\&} M),模 998244353998244353

这里,&\mathbin{\&} 表示按位 AND\rm{AND} 操作。

什么是按位 AND\rm{AND} 操作?非负整数 aabb 之间的按位 AND\rm{AND} 操作的结果 x=a&bx = a \mathbin{\&} b 定义如下:

  • xx 是满足以下条件的唯一非负整数,对于所有非负整数 kk

  • 如果 aa 的二进制表示中的 2k2^k 位和 bb 的二进制表示中的 2k2^k 位都是 11,那么 xx 的二进制表示中的 2k2^k 位是 11

  • 否则,xx 的二进制表示中的 2k2^k 位是 00

例如,3=11(2)3=11_{(2)}5=101(2)5=101_{(2)},所以 3&5=13 \mathbin{\&} 5 = 1。什么是 popcount\rm{popcount}popcount\rm{popcount}(x)(x) 表示 xx 的二进制表示中 11 的数量。 例如,13=1101(2)13=1101_{(2)},所以 popcount\rm{popcount}(13)=3(13) = 3

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

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 AND\rm{AND} operation? The result x=a&bx = a \mathbin{\&} b of the bitwise AND\rm{AND} operation between non-negative integers aa and bb 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 popcount\rm{popcount}? popcount\rm{popcount}(x)(x) represents the number of 11s in the binary representation of xx.
For example, 13=1101(2)13=1101_{(2)}, so popcount\rm{popcount}(13)=3(13) = 3.

Constraints

  • NN is an integer between 00 and 26012^{60} - 1, inclusive.
  • MM is an integer between 00 and 26012^{60} - 1, inclusive.

Input

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

NN MM

Output

Print the answer as an integer.

Sample Input 1

4 3

Sample Output 1

4
  • 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.

Sample Input 2

0 0

Sample Output 2

0

It is possible that N=0N = 0 or M=0M = 0.

Sample Input 3

1152921504606846975 1152921504606846975

Sample Output 3

499791890

Remember to compute the result modulo 998244353998244353.