A1323 | [COCI-2015_2016-contest6]#6 SAN
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Anica is having peculiar dream. She is dreaming about an infinite board. On that board, an infite table consisting of infinite rows and infinite columns containing infinite numbers is drawn. Interestingly, each number in the table appears a finite number of times.
The table is of exceptionally regular shape and its values meet the requirements of a simple recursive relation. The first cell of each row contains the ordinal number of that row. A value of a cell that is not in the first column can be calculated by adding up the number in the cell to the left of it and that same number, only written in reverse (in decimal representation).
Formally, if A(i, j) denotes the value in the i th row and the j th column, it holds:
• A(i, 1) = i
• A(i, j) = A(i, j − 1) + rev1 (A(i, j − 1)), for each j > 1 1 2 4 8 16 77 154 2 4 8 16 77 154 605 3 6 12 33 66 132 363 . . .
4 8 16 77 154 605 1111 5 10 11 22 44 88 176 .
.
.
.
.
.
The first few rows and columns of the table.
Notice that the table is infinite only in 2 directions.
Anica hasn’t shown too much interest in the board and obliviously passed by it. Behind the board, she noticed a lamp that immediately caught her attention. Anica also caught the lamp’s attention, so the friendly ghost Božo came out of it.
“Anica! If you answer correctly to my Q queries, you will win a package of Dorina wafer or Domaćica cookies, based on your own choice! I wouldn’t want to impose my stance, but in my personal opinion, the Dorina wafer cookies are better. Each query will consist of two integers A and B. You must answer how many appearances of numbers from the interval [A, B] there are on the board.”
Unfortunately, Anica couldn’t give an answer to the queries and woke up.
“Ah, I didn’t win the Dorina cookies, but at least I have a task for COCI”, she thought and went along with her business.
The table is of exceptionally regular shape and its values meet the requirements of a simple recursive relation. The first cell of each row contains the ordinal number of that row. A value of a cell that is not in the first column can be calculated by adding up the number in the cell to the left of it and that same number, only written in reverse (in decimal representation).
Formally, if A(i, j) denotes the value in the i th row and the j th column, it holds:
• A(i, 1) = i
• A(i, j) = A(i, j − 1) + rev1 (A(i, j − 1)), for each j > 1 1 2 4 8 16 77 154 2 4 8 16 77 154 605 3 6 12 33 66 132 363 . . .
4 8 16 77 154 605 1111 5 10 11 22 44 88 176 .
.
.
.
.
.
The first few rows and columns of the table.
Notice that the table is infinite only in 2 directions.
Anica hasn’t shown too much interest in the board and obliviously passed by it. Behind the board, she noticed a lamp that immediately caught her attention. Anica also caught the lamp’s attention, so the friendly ghost Božo came out of it.
“Anica! If you answer correctly to my Q queries, you will win a package of Dorina wafer or Domaćica cookies, based on your own choice! I wouldn’t want to impose my stance, but in my personal opinion, the Dorina wafer cookies are better. Each query will consist of two integers A and B. You must answer how many appearances of numbers from the interval [A, B] there are on the board.”
Unfortunately, Anica couldn’t give an answer to the queries and woke up.
“Ah, I didn’t win the Dorina cookies, but at least I have a task for COCI”, she thought and went along with her business.
输入格式
The first line of input contains the integer Q (1 6 Q 6 105 ), the number of queries.
Each of the following Q lines contains two integers A and B (1 6 A 6 B 6 1010) that represent the interval from the query.
Each of the following Q lines contains two integers A and B (1 6 A 6 B 6 1010) that represent the interval from the query.
输出格式
The i th line of output must contain a single integer – the answer to the i th query.
输入输出样例
输入 #1
2 1 10 5 8
输出 #1
18 8
输入 #2
3 17 144 121 121 89 98
输出 #2
265 25 10
输入 #3
1 1 1000000000
输出 #3
1863025563
The i
th line of output must contain a single integer – the answer to the i
th query.
th line of output must contain a single integer – the answer to the i
th query.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted