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 n and m.
Count the number of ordered tuples (i,j,k), such that:
- 0≤i,j,k≤m, and
- There exist two integers x and y, such that (i⊕j)⋅x+(j⊕k)⋅y=n, where ⊕ denotes the bitwise XOR operation.
我独自前行,走向远方,在渐暗的光中徘徊,静候日落的最后一缕光芒。
——SHUN,《CHAKA》(Spotify 链接)
西蒙斯给了你两个整数 n 和 m。
请计算满足以下条件的有序三元组 (i,j,k) 的个数:
- 0≤i,j,k≤m,且
- 存在两个整数 x 和 y,使得 (i⊕j)⋅x+(j⊕k)⋅y=n,其中 ⊕ 表示按位异或运算。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line contains two integers n and m (1≤n≤109, 1≤m≤3⋅105) — the given integers.
It is guaranteed that the sum of m over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是测试用例的描述。
唯一的一行包含两个整数 n 和 m(1≤n≤109,1≤m≤3⋅105)——即给定的整数。
保证所有测试用例中 m 的总和不超过 3⋅105。
输出格式
For each test case, output a single integer — the number of ordered tuples (i,j,k) that satisfy the condition.
对于每个测试用例,输出一个整数——满足条件的有序三元组 (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 18 tuples that satisfy the conditions. For example:
- (2,1,2) is a valid tuple because the equation (2⊕1)⋅x+(1⊕2)⋅y=3 has an integer solution x=3, y=−2.
- (1,1,0) is also a valid tuple because the equation (1⊕1)⋅x+(1⊕0)⋅y=3 has an integer solution x=100, y=3.
- (2,0,2) is not a valid tuple because the equation (2⊕0)⋅x+(0⊕2)⋅y=3 has no integer solution.
- (1,1,1) is not a valid tuple because the equation (1⊕1)⋅x+(1⊕1)⋅y=3 has no integer solution.
- (3,2,1) is not a valid tuple because 3>2.
在第一个测试用例中,共有 18 个满足条件的三元组。例如:
- (2,1,2) 是一个合法的三元组,因为方程 (2⊕1)⋅x+(1⊕2)⋅y=3 存在整数解 x=3、y=−2。
- (1,1,0) 也是一个合法的三元组,因为方程 (1⊕1)⋅x+(1⊕0)⋅y=3 存在整数解 x=100、y=3。
- (2,0,2) 不是一个合法的三元组,因为方程 (2⊕0)⋅x+(0⊕2)⋅y=3 不存在整数解。
- (1,1,1) 不是一个合法的三元组,因为方程 (1⊕1)⋅x+(1⊕1)⋅y=3 不存在整数解。
- (3,2,1) 不是一个合法的三元组,因为 3>2。
输入解题思路,AI测评打分。不知道怎么写?