【题目链接】

          点击打开链接

【算法】

         数位DP

         和上一题 : HDU3555很像

【代码】

           

#include<bits/stdc++.h>
using namespace std;
#define MAXL 10

long long n,m;
long long a[MAXL],dp[MAXL][MAXL];

template <typename T> inline void read(T &x) {
        long long f = 1; x = 0;
        char c = getchar();
        for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
        for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
        x *= f;
}
template <typename T> inline void write(T x) {
    if (x < 0) { putchar('-'); x = -x; }
    if (x > 9) write(x/10);
    putchar(x%10+'0');
}
template <typename T> inline void writeln(T x) {
    write(x);
    puts("");
}
inline void getdp() {
        long long i,j,k;
        dp[0][0] = 1;
        for (i = 1; i <= MAXL; i++) {
                for (j = 0; j <= 9; j++) {
                        if (j == 4) continue;
                        for (k = 0; k <= 9; k++) {
                                if (k == 4) continue;
                                if (j == 6 && k == 2) continue;
                                dp[i][j] += dp[i-1][k]; 
                        }
                }            
        }
}
inline long long calc(long long n) {
        long long i,j,ans = 0;
        a[0] = 0;
        while(n) {
                a[++a[0]] = n % 10;
                n /= 10;
        }    
        a[a[0]+1] = 0;
        for (i = a[0]; i >= 1; i--) {
                for (j = 0; j < a[i]; j++) {
                        if (j == 4) continue;
                        if (a[i+1] == 6 && j == 2) continue;
                        ans += dp[i][j];
                }
                if (a[i] == 4) break;
                if (a[i+1] == 6 && a[i] == 2) break;
        }
        return ans;
}

int main() {
        
        getdp();
        while (true) {
                read(n); read(m);
                if (!n && !m) break;
                writeln(calc(m+1)-calc(n));    
        }
        
        return 0;
    
}