你甚至可以只开一维(划掉)
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define Ls t[p << 1]
#define Rs t[p << 1 | 1]
#define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn = 3e5 + 10;
const ll inf = 1e7;
ll mod = 1e9 + 7;
ll dp[15];
int a[10];
int dfs(int len, int last, int ismax)
{
int ans = 0, maxx;
if (!len)return 1;
if (!ismax && !last && dp[len] != -1)
return dp[len];
maxx = (ismax ? a[len] : 9);
for (int i = 0; i <= maxx; i++)
{
if (i == 4)continue;
if (last && i == 2)continue;
ans += dfs(len - 1, i == 6, ismax && i == maxx);
//cout << len << " " << i << " " << ans << endl;
}
if (!ismax && !last)dp[len] = ans;
return ans;
}
int main()
{
//freopen("C:\1.in", "r", stdin);
fastio;
int n, m;
while (cin >> n >> m, n, m)
{
memset(dp, -1, sizeof(dp));
int cnt = 0;
//m++;
n--;
while (n)
a[++cnt] = n % 10, n /= 10;
int ans = -dfs(cnt, 0, 1);
//cout << ans << " ";
memset(dp, -1, sizeof(dp));
//cout << endl;
cnt = 0;
while (m)
a[++cnt] = m % 10, m /= 10;
ans += dfs(cnt, 0, 1);
cout << ans << endl;
}
return 0;
}