The integer (decimal
representation) is represented as in the binary numeral
system. This allows us to define the rotation
to the right of a natural number as the operation that places the
last digit of the binary representation before the first one. If we thus
rotate the binary number to the right, we obtain the
binary number . A given natural number can also be
rotated to the right -fold. In this case successive rotations are
executed on the binary representation of the number. As such, the 4-fold
rotation to the right of 19 equals 7, as can be seen from the following
series of rotations.
If the binary representation of an integer
has leading zeroes after a (-fold) rotation to the right, the leading
zeroes are deleted.
The inverted operation that places the first
digit of the binary representation of an integer at the back, is logically
called a rotation to the left of
the integer. Analogous to a rotation to the right, an -fold rotation to
the left is defined as a repeated execution of a rotation to the left.
Hence, the -fold rotation to the left of the number 357 equals 91, as
can be seen from the following series of rotations.
Input
The input exists of two lines, the first
containing a number , and the second a number .
Output
Execute an -fold rotation of the number
, and write out the result of all intermediate steps. Execute a
rotation to the right if is positive, and a rotation to the left if
is negative. The following intermediate results must be written out:
the decimal representation of the number
the binary representation of the number
the binary representation of the number after
rotations, with leading zeroes removed
the decimal representation of the number after
rotations
Tip: use the built-in
Python functions bin
and int to convert the
decimal representation of an integer to its binary representation and vice versa.