A11251 | Salazar Slytherin's Locket
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Harry came to know from Dumbledore that Salazar Slytherin's locket is a horcrux. This locket was present earlier at 12 Grimmauld Place, the home of Sirius Black's mother. It was stolen from there and is now present in the Ministry of Magic in the office of Dolorous Umbridge, Harry's former Defense Against the Dark Arts teacher.
Harry, Ron and Hermione are infiltrating the Ministry. Upon reaching Umbridge's office, they observed a code lock with a puzzle asking them to calculate count of magic numbers between two integers $l$ and $r$ (both inclusive).
Harry remembered from his detention time with Umbridge that she defined a magic number as a number which when converted to a given base $b$ , all the digits from $0$ to $b-1$ appear even number of times in its representation without any leading zeros.
You have to answer $q$ queries to unlock the office. Each query has three integers $b_{i}$ , $l_{i}$ and $r_{i}$ , the base and the range for which you have to find the count of magic numbers.
Harry, Ron and Hermione are infiltrating the Ministry. Upon reaching Umbridge's office, they observed a code lock with a puzzle asking them to calculate count of magic numbers between two integers $l$ and $r$ (both inclusive).
Harry remembered from his detention time with Umbridge that she defined a magic number as a number which when converted to a given base $b$ , all the digits from $0$ to $b-1$ appear even number of times in its representation without any leading zeros.
You have to answer $q$ queries to unlock the office. Each query has three integers $b_{i}$ , $l_{i}$ and $r_{i}$ , the base and the range for which you have to find the count of magic numbers.
输入格式
First line of input contains $q$ ( $1<=q<=10^{5}$ ) — number of queries.
Each of the next $q$ lines contain three space separated integers $b_{i}$ , $l_{i}$ , $r_{i}$ ( $2<=b_{i}<=10$ , $1<=l_{i}<=r_{i}<=10^{18}$ ).
Each of the next $q$ lines contain three space separated integers $b_{i}$ , $l_{i}$ , $r_{i}$ ( $2<=b_{i}<=10$ , $1<=l_{i}<=r_{i}<=10^{18}$ ).
输出格式
You have to output $q$ lines, each containing a single integer, the answer to the corresponding query.
输入输出样例
输入 #1
2 2 4 9 3 1 10
输出 #1
1 2
输入 #2
2 2 1 100 5 1 100
输出 #2
21 4
In sample test case $1$ , for first query, when we convert numbers $4$ to $9$ into base $2$ , we get:
- $4=100_{2}$ ,
- $5=101_{2}$ ,
- $6=110_{2}$ ,
- $7=111_{2}$ ,
- $8=1000_{2}$ ,
- $9=1001_{2}$ .
Out of these, only base $2$ representation of $9$ has even number of $1$ and $0$ . Thus, the answer is $1$ .
- $4=100_{2}$ ,
- $5=101_{2}$ ,
- $6=110_{2}$ ,
- $7=111_{2}$ ,
- $8=1000_{2}$ ,
- $9=1001_{2}$ .
Out of these, only base $2$ representation of $9$ has even number of $1$ and $0$ . Thus, the answer is $1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted