题目传送门
#include <bits/stdc++.h>
using namespace std;
const int N = 32;
int l, r;
int a[N], al;
int f[N][N];
int dp(int pos, int st, int op) {
if (!pos) return 1;
if (!op && ~f[pos][st]) return f[pos][st];
int res = 0, up = op ? a[pos] : 9;
for (int i = 0; i <= up; i++)
if (i != 4 && (st != 6 || i != 2))
res += dp(pos - 1, st == -1 && !i ? -1 : i, op && i == a[pos]);
return op ? res : f[pos][st] = res;
}
int calc(int x) {
memset(f, -1, sizeof f);
al = 0;
while (x) a[++al] = x % 10, x /= 10;
//st:pre前序数
//-1: 前面全是0时,前序值=-1
return dp(al, -1, 1);
}
int main() {
while (cin >> l >> r, l || r)
cout << calc(r) - calc(l - 1) << endl;
return 0;
}