模板题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[15];
ll dp[15][2];
ll dfs(ll pos, ll sta, ll lim)
{
if(pos == -1)return 1;
if(lim == 0 && dp[pos][sta] != -1)return dp[pos][sta];
ll len = lim ? a[pos] : 9;
ll ans = 0;
for(ll i = 0; i <= len; i++)
{
if(i == 4)continue;
else if(i == 2)
{
if(sta == 1)continue;
else ans += dfs(pos - 1, 0, lim && i == a[pos]);
}
else if(i == 6)
{
ans += dfs(pos - 1, 1, lim && i == a[pos]);
}
else
{
ans += dfs(pos - 1, 0, lim && i == a[pos]);
}
}
if(lim == 0)dp[pos][sta] = ans;
return ans;
}
ll slove(ll x)
{
ll pos = 0;
while(x)
{
a[pos++] = x % 10;
x /= 10;
}
ll ans = dfs(pos - 1, 0, 1);
}
int main()
{
ll n, m, i, j, k;
while(scanf("%lld %lld", &n, &m) != EOF)
{
if(n == 0 && m == 0)break;
for(i = 0; i < 15; i++)
for(j = 0; j < 2; j++)dp[i][j] = -1;
ll ans = slove(m) - slove(n - 1);
printf("%lld\n", ans);
}
return 0;
}