CF1870F.Lazy Numbers
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given positive integers n and k. For each number from 1 to n, we write its representation in the number system with base k (without leading zeros) and then sort the resulting array in lexicographic order as strings. In the sorted array, we number the elements from 1 to n (i.e., indexing starts from 1). Find the number of values i such that the representation of number i is at the i-th position in the sorted array of representations.
Examples of representations: 1 in any number system is equal to 1, 7 with k=3 is written as 21, and 81 with k=9 is written as 100.
给定正整数 n 和 k。对从 1 到 n 的每个数,我们将其写成以 k 为底的进制表示(不带前导零),然后将得到的所有字符串按字典序排序。在排序后的数组中,我们对元素编号为 1 到 n(即下标从 1 开始)。求满足“数字 i 的进制表示恰好位于排序后数组的第 i 个位置”的 i 的个数。
进制表示示例:任意进制下 1 的表示均为 1;当 k=3 时,7 的表示为 21;当 k=9 时,81 的表示为 100。
输入格式
The first line contains a single integer t (1≤t≤103) — the number of test cases. This is followed by a description of the test cases.
The only line of each test case contains integers n and k (1≤n≤1018, 2≤k≤1018).
第一行包含一个整数 t(1≤t≤103),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 k(1≤n≤1018,2≤k≤1018)。
输出格式
For each test case, output a single integer — the number of values 1≤i≤n such that the representation of number i in the number system with base k is at the i-th position after sorting.
对于每个测试用例,输出一个整数——满足条件的 1≤i≤n 的个数:即数字 i 在 k 进制下的表示,在所有 1 到 n 的数字的 k 进制表示按字典序(或数值序?需结合上下文)排序后,恰好位于第 i 个位置。
输入输出样例
输入#1
8 2 2 4 2 6 4 33 2 532 13 780011804570805480 3788 366364720306464627 4702032149561577 293940402103595405 2
输出#1
2 2 1 3 1 3789 1 7
说明/提示
In the first test case, for numbers 1 and 2, their representations are at positions 1 and 2 respectively.
In the second test case, the sorted array is [12=1,102=2,1002=4,112=3], and only the representations of numbers 1 and 2 are at the required positions.
In the third test case, the sorted array is [14=1,104=4,114=5,124=6,24=2,34=3], and only the number 1 is at its position.
在第一个测试用例中,数字 1 和 2 的表示分别位于位置 1 和 2。
在第二个测试用例中,排序后的数组为 [12=1,102=2,1002=4,112=3],且仅有数字 1 和 2 的表示位于所要求的位置上。
在第三个测试用例中,排序后的数组为 [14=1,104=4,114=5,124=6,24=2,34=3],且仅有数字 1 位于其对应的位置上。
输入解题思路,AI测评打分。不知道怎么写?