

You are given a number N. Your goal is to convert the number into base 58.
The Base58 alphabet consists of the following characters: “123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz”
Each byte value from 0 to 57 maps to the alphabet above.
Conversion Eg: ( according to above mapping).
Base 10 | Base 58
0 | 1
1 | 2
10 | A
20 | L
30 | W
53 | u
The first line of the input contains ‘T’ denoting the number of test cases.
The first and the only line of each test case contains an integer N.
Output Format:
For each test case, print a single line containing a single integer denoting the number in the base 58.
The output of each test case will be printed in a separate line.
Note:
You do not need to input or print anything, as it has already been taken care of. Just implement the given function.
1 <= T <= 50
0 <= N <= 10 ^ 4
Time limit: 1 sec.
2
10
67
B
2A
In test case 1:
If we represent 10 in powers of 58, it will be, 10 = 10*(58^0)
10 in base 10 corresponds to B in base 58 ( according to the above mapping).
Thus our answer is: B
In test case 2:
If we represent 66 in powers of 58, it will be, 67 = 1*(58^1) + 9*(58^0)
1 in base 10 corresponds to 2 in base 58, 9 in base 10 corresponds to A in base 58.
Thus our answer is: 2A
3
4364
1786
6978
2JF
Xo
35K
Convert N into powers of 58.
You can represent the integers as powers of 58 and then convert them using the above mapping.
Eg: 4364 = 1 * (58 ^ 2)+ 17 * (58 ^ 1) + 14 * (58 ^ 0)
1 in base 10 = 2 in base 58, 17 in base 10 = 2 in base J, 14 in base 10 = 2 in base F
Therefore the answer will be: 2JF
Algorithm:
O(log58(N)), where ‘N’ is the given integer.
As we are repeatedly dividing the integer by 58, we will only have O( log58(N)) steps before the number reaches zero.
O(log58(N)), where ‘N’ is the given integer.
We create a new string whose length will be O(log58(N)).