Codeforces Round 387 (Div. 2)
F
Igor and Interesting Numbers
Codeforces
2500
原题
← E→
翻译中…

Igor likes hexadecimal notation and considers positive integer in the hexadecimal notation interesting if each digit and each letter in it appears no more than $*t*$ times. For example, if $*t* = 3$, then integers 13a13322, aaa, abcdef0123456789 are interesting, but numbers aaaa, abababab and 1000000 are not interesting.

翻译中…

Your task is to find the $*k*$-th smallest interesting for Igor integer in the hexadecimal notation. The integer should not contain leading zeros.

翻译中…

Input

翻译中…

The first line contains the two integers $*k*$ and $*t*$ ($1 ≤ *k* ≤ 2·10^{9}$, $1 ≤ *t* ≤ 10$) — the number of the required integer and the maximum number of times some integer or letter can appear in interesting integer.

翻译中…

It can be shown that the answer always exists for such constraints.

翻译中…

Output

翻译中…

Print in the hexadecimal notation the only integer that is the $*k*$-th smallest interesting integer for Igor.

翻译中…

Note

翻译中…

The first 20 interesting integers if $*t* = 1$: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, 10, 12, 13, 14, 15. So the answer for the first example equals 12.

翻译中…

样例

Input #1
17 1
Output #1
12
InputCopy OutputCopy
Input #2
1000000 2
Output #2
fca2c
InputCopy OutputCopy
题目信息
题号
747F
时间限制
2 s
内存限制
256 MB
标签
暴力
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。