Manthan, Codefest 17
E
Salazar Slytherin's Locket
Codeforces
2200
原题
← DF →
翻译中…

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.

翻译中…

Input

翻译中…

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}$).

翻译中…

Output

翻译中…

You have to output $*q*$ lines, each containing a single integer, the answer to the corresponding query.

翻译中…

Note

翻译中…

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$.

翻译中…

样例

Input #1
2
2 4 9
3 1 10
Output #1
1
2
InputCopy OutputCopy
Input #2
2
2 1 100
5 1 100
Output #2
21
4
InputCopy OutputCopy
题目信息
题号
855E
时间限制
2 s
内存限制
256 MB
标签
位运算
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。