#abc321c. C - 321-like Searcher

C - 321-like Searcher

Score : 300300 points

问题描述

一个正整数 xx 被称为321类数,当它满足以下条件时。这个定义与问题A中的定义相同。

  • xx 的各位数字从上到下严格递减。
  • 换句话说,若 xxdd 位数字,则对于每一个满足 1i<d1 \le i < d 的整数 ii,它满足以下条件:
    • xx 的第 ii 位数字)>>xx 的第 (i+1)(i+1) 位数字)。

注意,所有一位的正整数都是321类数。

例如,321321964109641011 都是321类数,但 123123210921098641186411 不是。

找出第 KK 小的321类数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

A positive integer xx is called a 321-like Number when it satisfies the following condition. This definition is the same as the one in Problem A.

  • The digits of xx are strictly decreasing from top to bottom.
  • In other words, if xx has dd digits, it satisfies the following for every integer ii such that 1i<d1 \le i < d:
    • (the ii-th digit from the top of xx) >> (the (i+1)(i+1)-th digit from the top of xx).

Note that all one-digit positive integers are 321-like Numbers.

For example, 321321, 9641096410, and 11 are 321-like Numbers, but 123123, 21092109, and 8641186411 are not.

Find the KK-th smallest 321-like Number.

Constraints

  • All input values are integers.
  • 1K1 \le K
  • At least KK 321-like Numbers exist.

Input

The input is given from Standard Input in the following format:

KK

Output

Print the KK-th smallest 321-like Number as an integer.

Sample Input 1

15

Sample Output 1

32

The 321-like Numbers are (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,)(1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) from smallest to largest.
The 1515-th smallest of them is 3232.

Sample Input 2

321

Sample Output 2

9610

Sample Input 3

777

Sample Output 3

983210

update @ 2024/3/10 01:40:29

}