Problems > All Digits at Most Three

All Digits at Most Three

Difficulty: 1400 4000 ms 128 MB

digit-dp

Count integers in [L, R] all of whose digits are at most 3.

Input: one line with two integers L and R.

Output: the count in [L, R].

Constraints:

  • 1 ≤ L ≤ R ≤ 1018

Sample Tests

Input 1
1 40
Output 1
15
Input 2
20 50
Output 2
8

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.