CF1245F.Daniel and Spring Cleaning
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute 1+3 using the calculator, he gets 2 instead of 4. But when he tries computing 1+4, he gets the correct answer, 5. Puzzled by this mystery, he opened up his calculator and found the answer to the riddle: the full adders became half adders!
So, when he tries to compute the sum a+b using the calculator, he instead gets the xorsum a⊕b (read the definition by the link: https://en.wikipedia.org/wiki/Exclusive_or).
As he saw earlier, the calculator sometimes gives the correct answer. And so, he wonders, given integers l and r, how many pairs of integers (a,b) satisfy the following conditions: $$a + b = a \oplus b$$ $$l \leq a \leq r$$ $$l \leq b \leq r$$
However, Daniel the Barman is going to the bar and will return in two hours. He tells you to solve the problem before he returns, or else you will have to enjoy being blocked.
丹尼尔在春季大扫除时,发现了一台他非常喜爱的老式计算器。然而,这台计算器似乎坏了:当他用它计算 1+3 时,得到的结果是 2,而不是正确的 4;但当他计算 1+4 时,却得到了正确答案 5。为解开这个谜团,他拆开了计算器,终于找到了原因:原本的全加器(full adders) 全部变成了半加器(half adders)!
因此,当他用这台计算器计算和 a+b 时,实际得到的是异或和(xorsum) a⊕b(异或运算的定义参见:https://en.wikipedia.org/wiki/Exclusive_or)。
正如他之前所观察到的,这台计算器有时仍会给出正确结果。于是他开始思考:给定整数 l 和 r,有多少对整数 (a,b) 满足以下条件?
a+b=a⊕b
l≤a≤r
l≤b≤r
然而,酒保丹尼尔马上要去酒吧,两小时后才会回来。他要求你在他回来之前解决这个问题,否则你就得“享受”被封禁的待遇了。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of testcases.
Then, t lines follow, each containing two space-separated integers l and r (0≤l≤r≤109).
第一行包含一个整数 t(1≤t≤100)—— 表示测试用例的数量。
接下来有 t 行,每行包含两个以空格分隔的整数 l 和 r(0≤l≤r≤109)。
输出格式
Print t integers, the i-th integer should be the answer to the i-th testcase.
输出 t 个整数,其中第 i 个整数应为第 i 个测试用例的答案。
输入输出样例
输入#1
3 1 4 323 323 1 1000000
输出#1
8 0 3439863766
说明/提示
a⊕b denotes the bitwise XOR of a and b.
For the first testcase, the pairs are: (1,2), (1,4), (2,1), (2,4), (3,4), (4,1), (4,2), and (4,3).
a⊕b 表示 a 与 b 的按位异或(XOR)运算。
对于第一个测试用例,满足条件的数对为:(1,2)、(1,4)、(2,1)、(2,4)、(3,4)、(4,1)、(4,2) 和 (4,3)。
输入解题思路,AI测评打分。不知道怎么写?