No.2865 Base 10 Subsets 2
タグ : / 解いたユーザー数 102
作問者 :
寝癖
👑 Story
You work as an assistant for Yu~-san's research on parallel worlds... and one day, you and Yu~-san got pulled into one of those parallel worlds together.
Yu~-san looked around and noticed something. "The way numbers are counted in this world is really unpleasant..."
In our world, base $10$ is generally used, and no digit exceeds $9$. In this world, however, it seems that a separate upper limit is set for each digit, and values are counted so as not to exceed those limits.
"It's just like the imperial system. All right, you there, write me some code that can immediately compute the $K$-th smallest value among the numbers of this world. Oh, what on earth is that..?"
Having made the request, Yu~-san apparently spotted something intriguing in this world and ran off into the distance with sparkling eyes. ...Let's get the requested code written before Yu~-san comes back.
Problem Statement
We say that $B$ is a subset of $A$ in base ten if, at every digit in base ten, the value of $B$ is at most that of $A$.
More formally, it is defined as follows.
The ways to represent $A$ as $a_0\times 10^0 + a_1 \times 10^1 +\dots$ and $B$ as $b_0 \times 10^0 + b_1 \times 10^1 +\dots$ ( $0$ $\leq a_i , b_i \leq$ $9$ )
are each uniquely determined, and in these representations, $a_i \geq b_i$ holds for every non-negative integer $i$.
You are given a non-negative integer $N$ and a positive integer $K$. Print the $K$-th smallest among the non-negative integers that are subsets of $N$ in base ten.
Input
$N\ K$
Constraints
- $0\leq N\leq 10^{18}$
- $1\leq K\leq 10^{18}$
- There exist at least $K$ non-negative integers that are subsets of $N$ in base ten.
Output
Print the answer on one line, followed by a newline.
Sample
Sample 1
Input
12 3
Output
2
The numbers that are subsets of $12$ in base ten are, in ascending order, $0,1,2,10,11,12$.
Therefore, print $2$, which is the $3$-rd smallest among them.
Sample 2
Input
0 1
Output
0
Print $0$, the only subset of $0$ in base ten.
Sample 3
Input
1000000000000000000 2
Output
1000000000000000000
Note that the answer may not fit in a $32$-bit integer type.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。