1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cmath>
#include <iostream>

#define _optimize   \
  std::cin.tie(0);  \
  std::cout.tie(0); \
  std::ios::sync_with_stdio(0);

long long solve(long long l, long long r) {
  long long counter = 0;
  for (long long i = l; i <= r; ++i) {
    int width = std::log10(i) + 1;
    bool is_valid = true;
    int num = i;
    while (width-- && is_valid) {
      int sub_num = num % 10;
      num /= 10;
      if (sub_num == 0 || i % sub_num != 0) is_valid = false;
    }
    counter += is_valid;
  }
  return counter;
}

int main() {
  _optimize;
  long long l, r;
  std::cin >> l >> r;
  std::cout << solve(l, r) << "\n";
  return 0;
}