P27600 [洛谷] [GESP202309 Level 4] Variable-Length Encoding
普及
题目描述

Problem Description

Xiao Ming has just learned three methods of integer encoding: original code, one's complement, and two's complement, and he understands that computers typically store integers using two's complement. However, he always feels that numbers as large as $2^{31}-1$ are rarely used in daily life, and even common numbers like $0\sim 100$ also need to be represented using a 4-byte two's complement, which seems quite wasteful.

Eager to learn, Xiao Ming discovered a variable-length encoding method for positive integers through his research. The rules of this encoding method are as follows:

  1. For a given positive integer, first express it in binary form. For example, $(0)_{10} = (0)_2$, $(926)_{10} = (1110011110)_2$.

  2. Divide the binary number from the least significant bit to the most significant bit into groups of 7 bits each, padding with zeros at the higher positions if less than 7 bits are available. For example, $(0)_2$ becomes a single group of $0000000$, and $(1110011110)_2$ becomes two groups of $0011110$ and $0000111$.

  3. Starting from the group representing the least significant bits, add a most significant bit to each group. If this group is the last one, fill the most significant bit with $0$, otherwise fill it with $1$. Thus, the variable-length encoding for $0$ is a single byte of $00000000$, and for $926$ it is two bytes of $10011110$ and $00000111$.

This encoding method can use fewer bytes to represent smaller numbers and more bytes to represent very large numbers. For example, the binary representation of $987654321012345678$ is $(0001101 \ 1011010 \ 0110110 \ 1001011 \ 1110100 \ 0100110 \ 1001000 \ 0010110 \ 1001110)_2$, so its variable-length encoding is (in hexadecimal) CE 96 C8 A6 F4 CB B6 DA 0D, totaling 9 bytes.

Can you write a program to find the variable-length encoding for a positive integer?

Input Format

The first line of input contains a positive integer $N$. It is guaranteed that $0 \le N \le 10^{18}$.

Output Format

Output a single line, listing each byte of the variable-length encoding for $N$, each byte represented in 2-digit hexadecimal (with A-F in uppercase), separated by spaces.

Sample Input and Output

Sample Input #1

0

Sample Output #1

00

Sample Input #2

926

Sample Output #2

9E 07

Sample Input #3

987654321012345678

Sample Output #3

CE 96 C8 A6 F4 CB B6 DA 0D
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
0
样例输出
00