Base K
InterviewTime limit1sMemory limit128 MB
Convert each n to base k and report whether every digit from 0 to k-1 appears, formatting the output line exactly as specified.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Simulation, String
- Solved
- No attempts yet
Problem
We are used to the decimal positional notation for representing numbers, which uses 10 digits, from 0 to 9. However, there is nothing special about 10, and we can just as easily use any other base. For example, base-2 (binary) uses only two digits, 0 and 1, while base-16 (hexadecimal) uses - and (representing ten, eleven, twelve, thirteen, fourteen, and fifteen); both notations are common in computing.
More generally, a base- representation uses digits, through . If a number is written in base- as , then
where the subscript denotes that the number is written in base-. For example,
- (here represents fourteen in base-16)
Given two integers and , decide whether the base- representation of contains every digit from to .
For example, the base-3 representation of 15 is (), which contains all three digits 0, 1, 2. In contrast, the base-4 representation of 18 is (), which contains only 0, 1, 2 and is missing 3, so it does not contain all digits.
The base- representation is the standard one, without leading zeros. Therefore the digit 0 must actually appear somewhere in the middle of the number. For instance, 123456789 in base-10 contains only 1 through 9 and no 0, so it does not contain all digits (we do not pad it as 0123456789).
Digits with value 10 or greater are written as lowercase letters: , , , .
Input
The first line contains the number of test cases (). Each of the next lines contains one test case: two integers and , in that order, separated by a space. It is guaranteed that and .
Output
For each test case, print one line. Let be the base- representation of . If contains every digit from to , print
Base-<k> representation of <n> is <r>; contains all digits.
Otherwise, print
Base-<k> representation of <n> is <r>; does not contain all digits.
Replace <k>, <n>, and <r> with the actual values.