#P1017. [NOIP 2000 提高组] 进制转换
[NOIP 2000 提高组] 进制转换
Description
We can represent a decimal number as the sum of each Arabic digit multiplied by a power of whose exponent is the position of that digit. For example, can be written as .
Similarly, a binary number can be written as the sum of each binary digit multiplied by a power of whose exponent is the position of that digit.
In general, any positive integer or negative integer can be chosen as the base of a numeral system. If the base is or , the required digits are .
For example, when , the digits are , regardless of whether the base is or . If the absolute value of the base exceeds , letters are commonly used to represent digits greater than . For instance, in base , represents , represents , represents , and so on.
In a negative-base system, is used as the base. For example, (in decimal) is equivalent to (base ), and it can be written as a sum of powers of :
$$(110001)_{-2}=1\times (-2)^5+1\times (-2)^4+0\times (-2)^3+0\times (-2)^2+0\times (-2)^1 +1\times (-2)^0$$Design a program that reads a decimal integer and the base of a negative-base system, and converts the decimal number into that negative-base representation.
Input Format
Each line of input contains two values.
The first is the decimal integer . The second is the base of the negative-base numeral system.
Output Format
Output the number in this negative-base system together with its base. If the absolute value of the base exceeds , represent digits greater than using uppercase letters as in hexadecimal.
30000 -2
30000=11011010101110000(base-2)
-20000 -2
-20000=1111011000100000(base-2)
28800 -16
28800=19180(base-16)
-25000 -16
-25000=7FB8(base-16)
Hint
Constraints
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号