Max's Anger Contest Series 2 P4 - Number Anger

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Memory limit: 1G

Author:
Problem type

While driving to Waterloo, Max sees a car with a phone number on it: XXX 888-7777.

Then, he wonders

How many numbers are there from [1, R] that have D consecutive digits that are the same (excluding leading zeros)?

Can you count these numbers for him?

Constraints

1 \le R \le 9 \times 10^{18}

1 \le D \le 18

Subtask 1 [30%]

1 \le R \le 10^{5}

Subtask 2 [70%]

No additional constraints.

Input Specification

The first line will contain an integer, R, the upper limit on the numbers to count.

The second line will contain an integer, D, the number of consecutive digits that are the same.

Output Specification

Output the count of numbers between [1, R] that have D consecutive digits that are the same.

Sample Input 1

111
2

Sample Output 1

12

Explanation for Sample 1

The twelve numbers are 11, 22, 33, 44, 55, 66, 77, 88, 99, 100, 110, 111.

Sample Input 2

9999
2

Sample Output 2

2619

Sample Input 3

9000000000000000000
6

Sample Output 3

1132973828026002

Comments

There are no comments at the moment.