#P12828. 「DLESS-2」XOR and Number Theory

    ID: 11733 远端评测题 500ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化中国剩余定理 CRT洛谷比赛

「DLESS-2」XOR and Number Theory

Description

Given two integers nn and mm. You need to find the sum of x2mod(y2xy)x^2\bmod(y^2-xy) over all pairs of integers (x,y)(x,y) that satisfy the following two conditions:

  • 1x<yn1\le x< y\le n
  • xy=gcd(x,y)mx\oplus y=\gcd(x,y)\le m

Here, \oplus denotes the bitwise XOR operation.

Since the result can be very large, output the answer modulo 109+710^9+7.

Input Format

There are multiple test cases. The first line contains a single positive integer TT, indicating the number of test cases.

For each test case, there is a single line containing two integers, nn and mm.

Output Format

For each test case, output a single line containing one integer, representing the answer modulo 109+710^9+7.

3
8 3
11 3
114514 11451
7
13
184193935

Hint

For all test data, it is guaranteed that:

  • 1T30001\le T\le 3000
  • 2n1092\le n\le 10^9
  • 1mn1\le m\le n
  • 1m1051\le \sum m\le 10^5

This problem uses subtasks for grading. The description for each subtask is as follows:

Subtask nn\le n\sum n\le m\sum m\le Points
11 10001000 1010
22 10410^4
33 10710^7 10510^5
44 5×1075\times10^7 2020
55 10910^9 ++\infty 10001000 1010
66 50005000
77 3×1043\times 10^4
88 10510^5 2020