PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000350. Đếm số đẹp trong đoạn (Beautiful Numbers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm số đẹp trong đoạn (Beautiful Numbers)

Beautiful Numbers

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer XX is beautiful if it is divisible by every nonzero decimal digit appearing in its own representation. Digit 0 imposes no condition.

For example, 120120 is beautiful because it is divisible by 11 and 22; the zero digit imposes no condition. The number 124124 is also beautiful because it is divisible by 11, 22, and 44. In contrast, 123123 is not beautiful because it is not divisible by its digit 22.

Given 1≤L≤R1\le L\le R, count the beautiful integers in the inclusive interval [L,R][L,R].

PHOJ adaptation: one interval per input file instead of the multiple-range wrapper in the original statement.

Input

One line contains integers L,RL,R.

Output

Print the exact count in [L,R][L,R], without modulo.

Subtasks

  • Subtask 1 (20 points): 1≤L≤R≤1051\le L\le R\le10^5.
  • Subtask 2 (30 points): 1≤L≤R≤10121\le L\le R\le10^{12}.
  • Subtask 3 (50 points): 1≤L≤R≤9⋅10181\le L\le R\le9\cdot10^{18}.

Examples

Example 1

Input

1 9

Output

9

Explanation

Every one-digit positive integer is divisible by its only nonzero digit, so all nine are beautiful.

Example 2

Input

12 15

Output

2

Explanation

Only 12 and 15 qualify. The value 13 is not divisible by digit 3, and 14 is not divisible by digit 4.