

This question is selected from Luogu question bank (). (2) Source program.įor (int i = 0 s ! = ‘\ 0’ I + +) / / N decimal integers are expanded by weight and converted to decimal integers num The idea of this example is to expand the input n-ary integer by weight and convert it to decimal integer, and then convert the resulting decimal integer to M-ary integer by “divide by m to get the remainder”. The basic method to convert R-base number to decimal number is to add the bits of R-base number by weight expansion. This sum is also known as “expansion by weight”. Generally speaking, for any r-ary number a n-1A n-2…A 1A 0It can be expressed as the following sum:Ī n-1×R n-1 +…+A 1×R 1+A 0×R 0(where R is the base) This process can be written as a simple cycle. The specific method is as follows: for decimal integer, divide the decimal integer to be converted and the quotient of each time by R continuously until the quotient is equal to 0, then the remainder of each time is the value from low to high. The basic method of converting decimal integers to r-ary integers is “divide by R and take remainder”. The third line is also a positive integer, representing the base m (2 ≤ m ≤ 16) of the number after conversion.Ī positive integer indicating the M-ary number after conversion.

If n > 10, the capital letter A-F is used to represent the number 10-15, and the decimal value corresponding to the n-base number is not more than 1000000000.

The first line is a positive integer, representing the base n (2 ≤ n ≤ 16) of the number to be converted. Please make a program to realize the data conversion between two different bases.
