#P9821. [ICPC2020 Shanghai R] Sum of Log

[ICPC2020 Shanghai R] Sum of Log

题目描述

Given two non-negative integers XX and YY, determine the value of

$$\sum_{i=0}^{X}\sum_{j=[i=0]}^{Y}[i\&j=0]\lfloor\log_2(i+j)+1\rfloor $$

modulo 109+710^9+7 where

  • &\& denotes bitwise AND;
  • [A][A] equals 1 if AA is true, otherwise 00;
  • x\lfloor x\rfloor equals the maximum integer whose value is no more than xx.

输入格式

The first line contains one integer T(1T105)T\,(1\le T \le 10^5) denoting the number of test cases.

Each of the following TT lines contains two integers X,Y(0X,Y109)X, Y\,(0\le X,Y \le 10^9) indicating a test case.

输出格式

For each test case, print one line containing one integer, the answer to the test case.

题目大意

给定两个非负整数 X,YX,Y,计算下列式子对 109+710^9+7 取模的值:

$$\sum\limits_{i=0}^{X}{\sum\limits_{j=[i=0]}^{Y}{[i \& j=0]\lfloor \log_2(i+j)+1\rfloor}} $$

其中:

  • &\& 表示按位与。
  • [A][A] 等于 11,当且仅当表达式 AA 为真;否则 [A][A] 等于 00
  • x\lfloor x \rfloor 表示不大于 xx 的最大整数。
3
3 3
19 26
8 17
14
814
278

提示

For the first test case:

  • Two (i,j)(i,j) pairs increase the sum by 1: (0,1),(1,0)(0, 1), (1, 0)
  • Six (i,j)(i,j) pairs increase the sum by 2: (0,2),(0,3),(1,2),(2,0),(2,1),(3,0)(0, 2), (0, 3), (1, 2), (2, 0), (2, 1), (3, 0)

So the answer is 1×2+2×6=141\times 2 + 2\times 6 = 14.