Problems > Numbers That Contain D

Numbers That Contain D

Difficulty: 1600 2000 ms 128 MB

math

How many integers in [1, N] contain the digit D at least once?

Input: one line with two integers N and D.

Output: the count of integers containing D.

Constraints:

  • 1 ≤ N ≤ 1018
  • 0 ≤ D ≤ 9

Sample Tests

Input 1
25 2
Output 1
8
Input 2
10 0
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.