#P1017. Negative Base Conversion
Negative Base Conversion
Negative Base Conversion
In this problem, you are given a decimal integer and a positive integer R. You need to convert the given number into its representation in negative base, i.e. base (-R).
Every number can be expressed as the sum of digits multiplied by powers of the base. For instance, a decimal number like $$123 = 1 \times 10^2 + 2 \times 10^1 + 3 \times 10^0$$. Similarly, when the base is (-R), the representation uses powers of (-R).
For example, the decimal number (-15) can be represented in base (-2) as follows:
The digits used in the representation range from 0 to \(R-1\). If \(R > 10\), digits larger than 9 are represented by uppercase letters (A, B, C, …). ## inputFormat The input consists of a single line containing two integers separated by spaces: the decimal integer to be converted and the positive integer R. The conversion must be done using base \(-R\). ## outputFormat Output the representation of the given decimal number in base \(-R\). ## sample
0 2
0
$$