CF2205G.Simons and Diophantus Equation

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

I walk alone, into distance, through the fading light, biding my time for the sunset's final light.

— SHUN, CHAKA

Simons has given you two integers nn and mm.

Count the number of ordered tuples (i,j,k)(i, j, k), such that:

  • 0≤i,j,k≤m0\le i, j, k\le m, and
  • There exist two integers xx and yy, such that (i⊕j)⋅x+(j⊕k)⋅y=n(i \oplus j) \cdot x + (j \oplus k) \cdot y = n, where ⊕\oplus denotes the bitwise XOR operation.

我独自前行,走向远方,在渐暗的光中徘徊,静候日落的最后一缕光芒。

——SHUN,《CHAKA》(Spotify 链接)

西蒙斯给了你两个整数 nn 和 mm。

请计算满足以下条件的有序三元组 (i,j,k)(i, j, k) 的个数:

  • 0≤i,j,k≤m0\le i, j, k\le m,且
  • 存在两个整数 xx 和 yy,使得 (i⊕j)⋅x+(j⊕k)⋅y=n(i \oplus j) \cdot x + (j \oplus k) \cdot y = n,其中 ⊕\oplus 表示按位异或运算。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line contains two integers nn and mm (1≤n≤1091\le n\le 10^9, 1≤m≤3⋅1051\le m\le 3\cdot 10^5) — the given integers.

It is guaranteed that the sum of mm over all test cases does not exceed 3⋅1053\cdot10^5.

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

唯一的一行包含两个整数 nn 和 mm(1≤n≤1091\le n\le 10^9,1≤m≤3⋅1051\le m\le 3\cdot 10^5)——即给定的整数。

保证所有测试用例中 mm 的总和不超过 3⋅1053\cdot10^5。

输出格式

For each test case, output a single integer — the number of ordered tuples (i,j,k)(i,j,k) that satisfy the condition.

对于每个测试用例,输出一个整数——满足条件的有序三元组 (i,j,k)(i,j,k) 的个数。

输入输出样例

  • 输入#1

    5
    3 2
    4 6
    1 1
    7 20
    720 2025

    输出#1

    18
    254
    6
    5558
    7864357450

说明/提示

In the first test case, there are 1818 tuples that satisfy the conditions. For example:

  • (2,1,2)(2,1,2) is a valid tuple because the equation (2⊕1)⋅x+(1⊕2)⋅y=3(2\oplus 1)\cdot x+(1\oplus 2)\cdot y=3 has an integer solution x=3x=3, y=−2y=-2.
  • (1,1,0)(1,1,0) is also a valid tuple because the equation (1⊕1)⋅x+(1⊕0)⋅y=3(1\oplus 1)\cdot x+(1\oplus 0)\cdot y=3 has an integer solution x=100x=100, y=3y=3.
  • (2,0,2)(2,0,2) is not a valid tuple because the equation (2⊕0)⋅x+(0⊕2)⋅y=3(2\oplus 0)\cdot x+(0\oplus 2)\cdot y=3 has no integer solution.
  • (1,1,1)(1,1,1) is not a valid tuple because the equation (1⊕1)⋅x+(1⊕1)⋅y=3(1\oplus 1)\cdot x+(1\oplus 1)\cdot y=3 has no integer solution.
  • (3,2,1)(3,2,1) is not a valid tuple because 3>23 \gt 2.

在第一个测试用例中,共有 1818 个满足条件的三元组。例如:

  • (2,1,2)(2,1,2) 是一个合法的三元组,因为方程 (2⊕1)⋅x+(1⊕2)⋅y=3(2\oplus 1)\cdot x+(1\oplus 2)\cdot y=3 存在整数解 x=3x=3、y=−2y=-2。
  • (1,1,0)(1,1,0) 也是一个合法的三元组,因为方程 (1⊕1)⋅x+(1⊕0)⋅y=3(1\oplus 1)\cdot x+(1\oplus 0)\cdot y=3 存在整数解 x=100x=100、y=3y=3。
  • (2,0,2)(2,0,2) 不是一个合法的三元组,因为方程 (2⊕0)⋅x+(0⊕2)⋅y=3(2\oplus 0)\cdot x+(0\oplus 2)\cdot y=3 不存在整数解。
  • (1,1,1)(1,1,1) 不是一个合法的三元组,因为方程 (1⊕1)⋅x+(1⊕1)⋅y=3(1\oplus 1)\cdot x+(1\oplus 1)\cdot y=3 不存在整数解。
  • (3,2,1)(3,2,1) 不是一个合法的三元组,因为 3>23 \gt 2。

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

首页