[ Strona główna | Archiwum zadań ]

Problem: Hexadecimal Numbers

The base of the hexadecimal system is 16. In order to write down
numbers in this system one uses 16 digits 0,1,...,9,A,B,C,D,E,F.
The capital letters A,..,F stands for 10,..,15, respectively.
For instance the value of the hexadecimal number CF2 is
12 * 16^{2} + 15 * 16 + 2 = 3314 in the decimal system. Let X be
the set of all positive integers whose hexadecimal representations
have at most 8 digits and do not contain repetitions of any digit.
The most significant digit in such a representation is not zero.
The largest element in X is the number with the hexadecimal
representation FEDCBA98, the second largest is the number FEDCBA97,
the third is FEDCBA96 and so forth.

**Task**

Write a program that:

- reads positive integer n from the text file HEX.IN, n does not exceed the number of elements of X;
- finds the n-th largest element of X;
- writes the result to the text file HEX.OUT.

**Input**

The first line of the file HEX.IN contains integer n in the decimal representation.

**Output**

Your program should write the n-th largest element in X in the hexadecimal representation to the first line of the text file HEX.OUT

**Example**

For the text file HEX.IN:

11the correct solution is the text file HEX.OUT:

FEDCBA87

[ Strona główna | Archiwum zadań ]