The code for converting decimal numbers to Roman was on Wikipedia , so I'm not going to explain it.
Since we have the upper limit 1015 for all of our numbers , we can first convert them to decimal (and store the answer in a 64-bit integer) and then to the target base.
For converting a number to decimal we first set the decimal variable to 0, then at each step we multiply it by the base and add the left-most digit's equivalent in base 10.
We had some tricky test cases for this one which got many people :
test #51:
2 10
0
many codes printed nothing for this one, this was also the most used hack for this problem
test #54:
12 2
000..00A
a sample of having initial zeros in input
test #55:
17 17
0000000...000
There were many people who just printed the input if bases were equal
there were two nice extremal hacks:
2 R
101110111000
and
10 2
1000000000000000