#P4222. [CQOI2012] 编号

[CQOI2012] 编号

Description

You need to assign numbers to a batch of products, where each number is a 77-digit hexadecimal number (composed of 00 to 99, aa to ff).

To prevent mistakes during manual processing, any two numbers must differ in at least three corresponding positions.

The first number is 00000000000000, the second is the smallest number that does not violate the above rule, … Each time a new number is assigned, always choose the smallest number that does not conflict with the previous numbers (note that the numbers are hexadecimal, so they can be compared by value).

Following this rule, the first few numbers are:

$$0000000,0000111,0000222,…,0000fff,0001012,0001103,0001230,0001321,0001456,…$$

Given kk, your task is to find the kk-th smallest number.

Input Format

One integer kk on a single line.

Output Format

Output the kk-th smallest number (letters must be lowercase). The input guarantees that this number exists.

20
0001321

Hint

For 15% of the testdata, k200k \leq 200;

For 35% of the testdata, k10000k \leq 10000;

For 60% of the testdata, k200000k \leq 200000.

For 100% of the testdata, k1048576k \leq 1048576.

Translated by ChatGPT 5