Killjee and base X

5

1 votes
Combinatorics, Easy, Math
Problem

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 ai 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 ni=0ai for given n and x.

INPUT CONSTRAINTS
1t103 1n1015 1k104

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.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

in base 2, 0 can be written as 0, 1 can be written as 1, 2 can be written as 10, 3 can be written as 11, 4 can be written as 100. so sum of total number of digits is 1+1+2+2+3=9

Editor Image

?