不要 4 和 62
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;
int arr[20],dp[20][3];
int pow( int num )
{
int ans = 1;
for( int i = 0; i < num;i++ )
ans*=10;
return ans;
}
int DFS( int pos,int flag, int end )
{
if( pos == -1 ){return (flag == 2);}
if( !end && dp[pos][flag] != -1 ) return dp[pos][flag];
if( !end && flag == 2 ) return dp[pos][flag] = pow(pos+1);
int limit = end?arr[pos]:9,ans = 0;
for( int i = 0; i <= limit; i++ )
{
int tab = flag;
if( flag == 1 && i == 2 )tab = 2;
else if( i == 4 ) tab = 2;
else if( flag == 1 && i != 6 ) tab = 0;
else if( flag != 2 && i == 6 ) tab = 1;
ans += DFS( pos-1,tab,end&&(i==limit) );
}
if( !end ) dp[pos][flag] = ans;
return ans;
}
int work( int num )
{
int k = 0;
while( num )
{
arr[k++] = num%10;
num = num/10;
}
memset( dp,-1,sizeof(dp) );
return DFS( k-1,0,1 );
}
int main( )
{
int N,M;
while( scanf("%d%d",&N,&M) != EOF )
{
if( N == 0 && M == 0 ) break;
printf("%d\n",M - N + 1 - (work(M) - work(N-1)));
}
return 0;
}