Killjee and base X
Practice
5 (1 votes)
Combinatorics
Easy
Math
Problem
42% Success 4742 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Killjee is learning about representation of numbers in different bases. Pahi seeing this got jealous and gave killjee a very difficult problem.
Let's call \(a_i\) be number of digits in x-base representation of i.X-base representation is representation of a number in base x.
Killjee needs to find \(\displaystyle\sum_{i=0}^{n} {a_i}\) for given n and x.
INPUT CONSTRAINTS
\(1 \le t \le 10^3\)
\(1 \le n \le 10^{15}\)
\(1 \le k \le 10^4\)
INPUT FORMAT
First line of input contain a single integer t.t lines follow each containing two space separated integers n and k.
OUTPUT FORMAT
For each test case output a single integer, answer to the problem.
Print integers as space separated integers on single line.
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
CombinatoricsEasyMath
Points:30
6 votes
Tags:
Data StructuresEasyOne-dimensionalapprovedhiring
Points:30
3 votes
Tags:
CombinatoricsEasyFibonacci numberMath
Editorial