#H. F - Digits Paradise in Hexadecimal

    传统题 2000ms 1024MiB

F - Digits Paradise in Hexadecimal

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

F - Digits Paradise in Hexadecimal

Score : $600$ points

Problem Statement

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)$.

Constraints

  • $1 \le N \lt {16}^{2 \times 10^5}$
  • $N$ is given in hexadecimal notation without leading 0s.
  • $1 \le K \le 16$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Here, $N$ is in hexadecimal notation.

Output

Print the count modulo $10^9 + 7$.


10 1
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.


FF 2
225

All of the $255$ numbers except the following $30$ numbers contain two distinct digits in hexadecimal: $1, 2, 3, \dots, \mathrm{E}, \mathrm{F}, 11, 22, 33, \dots, \mathrm{EE}, \mathrm{FF}$ in hexadecimal.


100 2
226

1A8FD02 4
3784674

DEADBEEFDEADBEEEEEEEEF 16
153954073

Print the count modulo $(10^9 + 7)$.

2024春季入门组刷题营(八)

未参加
状态
已结束
规则
IOI
题目
8
开始于
2024-5-5 13:00
结束于
2024-5-5 15:00
持续时间
2 小时
主持人
参赛人数
11