Look (differently) and say
Statement
Two friends Jaanu and Anu are playing a look and say game but in by looking at the representation in other bases.
<<Jaanu>>: You will be given two integers [[N]] representing the number and a base [[B]] for which you have to find the twin for [[N]].
It goes as follows
Let's say that you are given the number {{9}} and a base {{2}}
Hence its binary representation is {{1001}}
Now, we can see that there is <<one>> {{1}} <<two>> {{0}}s and again <<one>> {{1}}. So, it goes
{{112011}}.
Now convert it from the minimum base that can be used to represent this number. Here, it is clearly {{3}}.
Hence, the decimal representation would be {{382}}
<<Anu>> : What if you cheat and give {{1}} and {{0}} as bases?
<<Jaanu>> : If I give {{1}}, then just put <<that many number of>> {{1}}s as the number's representation like {{9}} = {{111111111}} and then do the same.
If I give {{0}}, then just print the alphabet represented by each digits {{A = 0}}, {{B = 1}}, etc.
<<Anu>>: What if you give a base [[B]] less than {{0}} ?
<<Jaanu>>: Just print {{Invalid}}
<<Anu>>: What if there are <<alphabets>> in the first conversion?
<<Jaanu>>: Just follow the base {{36}} rule wherein you take {{A}} as {{10}}, {{B}} as {{11}} and so on. That is if you get the conversion result as say, {{14ne0hx}}, then the minimum base will be {{34}} because obviously {{x}} is the maximum which by the base {{36}} rule has an order of {{24}} in the alphabet + {{10}} (because {{0}}-{{9}} ({{10}} numbers) occupy first and then alphabets follow and hence shifted by {{10}}) = {{34}}
Input description
First line : Integer [[N]]
Second line : Base [[B]]
Output description
Integer after conversion of the given number as per the above rule or an alphabet sequence
Constraints
0 <= [[N]] < 10^21
[[B]] < 37
Game modes
Test cases
Test 1 Test
Input
59
8
Output
971
Validator 1 Validator
Input
61
7
Output
479
Test 2 Test
Input
531
16
Output
1623
Validator 2 Validator
Input
428
0
Output
ECI
Test 3 Test
Input
87
14
Output
647
Validator 3 Validator
Input
77
7
Output
3980
Test 4 Test
Input
1356
29
Output
6737389
Validator 4 Validator
Input
562
36
Output
20147
Test 5 Test
Input
9416
28
Output
716243
Validator 5 Validator
Input
174819136
34
Output
19524265400835940
Test 6 Test
Input
19746193
32
Output
12729886902323
Validator 6 Validator
Input
963989
36
Output
36492983147
Test 7 Test
Input
74
-7
Output
Invalid
Validator 7 Validator
Input
84
-309
Output
Invalid
Test 8 Test
Input
103503432054
0
Output
BADFADEDCAFE
Validator 8 Validator
Input
502034
0
Output
FACADE
Test 9 Test
Input
745241763221720
1
Output
266805489245825
Validator 9 Validator
Input
741
1
Output
3849
Solution language
Solution
Stub generator input