9730: ABC194 —— F - Digits Paradise in Hexadecimal
[Creator : ]
Description
In this problem, hexadecimal notations use `0`, ..., `9`, `A`, ..., `F`, representing the values zero through fifteen, respectively.
Unless otherwise specified, all notations of numbers are decimal notations.
How many integers between $1$ and $N$ (inclusive) have exactly $K$ distinct digits in the hexadecimal notation without leading zeros?
Print this count modulo $(10^9 + 7)$.
Unless otherwise specified, all notations of numbers are decimal notations.
How many integers between $1$ and $N$ (inclusive) have exactly $K$ distinct digits in the hexadecimal notation without leading zeros?
Print this count modulo $(10^9 + 7)$.
Input
Input is given from Standard Input in the following format:
```
$N$ $K$
```
Here, $N$ is in hexadecimal notation.
```
$N$ $K$
```
Here, $N$ is in hexadecimal notation.
Output
Print the count modulo $10^9 + 7$.
Constraints
- $1 \le N \lt {16}^{2 \times 10^5}$
- $N$ is given in hexadecimal notation without leading `0`s.
- $1 \le K \le 16$
- All values in input are integers.
- $N$ is given in hexadecimal notation without leading `0`s.
- $1 \le K \le 16$
- All values in input are integers.
Sample 1 Input
10 1
Sample 1 Output
15
The hexadecimal number N is 16 in decimal.
In hexadecimal, the integers between 1 and 16 are written as follows:
- 1 through 15: are 1-digit numbers in hexadecimal, containing one distinct digit.
- 16: is 10 in hexadecimal, containing two distinct digits.
Thus, there are 15 numbers that contain one distinct digit in hexadecimal.
Sample 2 Input
FF 2
Sample 2 Output
225
All of the 255 numbers except the following 30 numbers contain two distinct digits in hexadecimal: 1,2,3,…,E,F,11,22,33,…,EE,FF in hexadecimal.
Sample 3 Input
100 2
Sample 3 Output
226
1A8FD02 4
3784674
Sample 4 Input
DEADBEEFDEADBEEEEEEEEF 16
Sample 4 Output
153954073