X-base question

1

1 votes
Open, Open, Open, Medium, Combinatorics, Combinatorics basics, Basics of Combinatorics, Mathematics, Mathematics
Problem

Let ai be the number of digits in the x-base representation of i. The x-base representation is the representation of a number in base x.

Determine the ni=0ai for the provided n and x.

Input format

  • First line: A single integer t
  • Each of the next t lines: Two space-separated integers n and k

Output format
For each test case, print a single integer that represents the answer to the question. Print the integers as space-separated integers on a single line.

Constraints

1t103
1n1015
1k104

Sample Input
3
4 2
8 3
4 3
Sample Output
9
15
7
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

?