A13051 | Daniel and Spring Cleaning
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 \oplus b$ (read the definition by the link: [https://en.wikipedia.org/wiki/Exclusive\_or](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.
So, when he tries to compute the sum $a + b$ using the calculator, he instead gets the xorsum $a \oplus b$ (read the definition by the link: [https://en.wikipedia.org/wiki/Exclusive\_or](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.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 100$ ) — the number of testcases.
Then, $t$ lines follow, each containing two space-separated integers $l$ and $r$ ( $0 \le l \le r \le 10^9$ ).
Then, $t$ lines follow, each containing two space-separated integers $l$ and $r$ ( $0 \le l \le r \le 10^9$ ).
输出格式
Print $t$ integers, the $i$ -th integer should be the answer to the $i$ -th testcase.
输入输出样例
输入 #1
3 1 4 323 323 1 1000000
输出 #1
8 0 3439863766
$a \oplus 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)$ .
For the first testcase, the pairs are: $(1, 2)$ , $(1, 4)$ , $(2, 1)$ , $(2, 4)$ , $(3, 4)$ , $(4, 1)$ , $(4, 2)$ , and $(4, 3)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted