CF855E.Salazar Slytherin's Locket

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ll and rr (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 bb , all the digits from 00 to b1b-1 appear even number of times in its representation without any leading zeros.

You have to answer qq queries to unlock the office. Each query has three integers bib_{i} , lil_{i} and rir_{i} , the base and the range for which you have to find the count of magic numbers.

输入格式

First line of input contains qq ( 1<=q<=1051<=q<=10^{5} ) — number of queries.

Each of the next qq lines contain three space separated integers bib_{i} , lil_{i} , rir_{i} ( 2<=bi<=102<=b_{i}<=10 , 1<=li<=ri<=10181<=l_{i}<=r_{i}<=10^{18} ).

输出格式

You have to output qq 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 11 , for first query, when we convert numbers 44 to 99 into base 22 , we get:

  • 4=10024=100_{2} ,
  • 5=10125=101_{2} ,
  • 6=11026=110_{2} ,
  • 7=11127=111_{2} ,
  • 8=100028=1000_{2} ,
  • 9=100129=1001_{2} .

Out of these, only base 22 representation of 99 has even number of 11 and 00 . Thus, the answer is 11 .

首页