#P4222. [CQOI2012] 编号
[CQOI2012] 编号
Description
You need to assign numbers to a batch of products, where each number is a -digit hexadecimal number (composed of to , to ).
To prevent mistakes during manual processing, any two numbers must differ in at least three corresponding positions.
The first number is , 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 , your task is to find the -th smallest number.
Input Format
One integer on a single line.
Output Format
Output the -th smallest number (letters must be lowercase). The input guarantees that this number exists.
20
0001321
Hint
For 15% of the testdata, ;
For 35% of the testdata, ;
For 60% of the testdata, .
For 100% of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号