103212: [Atcoder]ABC321 C - 321-like Searcher

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:11 Solved:0

Description

Score : $300$ points

Problem Statement

A positive integer $x$ 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 $x$ are strictly decreasing from top to bottom.
  • In other words, if $x$ has $d$ digits, it satisfies the following for every integer $i$ such that $1 \le i < d$:
    • (the $i$-th digit from the top of $x$) $>$ (the $(i+1)$-th digit from the top of $x$).

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

For example, $321$, $96410$, and $1$ are 321-like Numbers, but $123$, $2109$, and $86411$ are not.

Find the $K$-th smallest 321-like Number.

Constraints

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

Input

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

$K$

Output

Print the $K$-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,\dots)$ from smallest to largest.
The $15$-th smallest of them is $32$.


Sample Input 2

321

Sample Output 2

9610

Sample Input 3

777

Sample Output 3

983210

Output

得分:300分

问题描述

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

  • $x$的数字从上到下严格递减。
  • 换句话说,如果$x$有$d$位数字,那么对于满足$1 \le i < d$的整数$i$,它满足以下条件:
    • (从$x$顶部的第$i$位数字)$>$(从$x$顶部的第$(i+1)$位数字)。

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

例如,$321$,$96410$和$1$是321型数,但$123$,$2109$和$86411$不是。

找到第$K$小的321型数。

约束

  • 所有的输入值都是整数。
  • $1 \le K$
  • 至少存在$K$个321型数。

输入

输入数据按照以下格式从标准输入给出:

$K$

输出

将第$K$小的321型数作为一个整数输出。


样例输入1

15

样例输出1

32

从最小到最大,321型数为$(1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots)$。
它们中第15小的是$32$。


样例输入2

321

样例输出2

9610

样例输入3

777

样例输出3

983210

HINT

第k个各位数字递减的数是多少?

加入题单

算法标签: