Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u

Description

62315 73418 88914

Input

Output

Sample Input

1 100

0 0

Sample Output

80

Source

AC代码：

#include <iostream>
#include <cstring>
using namespace std;
int dp[10][10];
void init()
{
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;//长度为i，开头为j满足条件的个数
for (int i = 1; i <= 7; i++)//len
for (int j = 0; j <= 9; j++)//digit[i]
{
if (j == 4)
continue;
for (int k = 0; k <= 9; k++)//digit[i - 1] 由于倒序存储，实际上是后一位数
if (!(k == 2 && j == 6))
dp[i][j] += dp[i - 1][k];
}
}
int solve(int n)
{
int digit[10], len = 0, ans = 0;
while (n)
{
digit[++len] = n % 10;
n /= 10;
}
digit[len + 1] = 0;
for (int i = len; i >= 1; i--)
{
for (int j = 0; j < digit[i]; j++)
if (j != 4 && !(j == 2 && digit[i + 1] == 6))
ans += dp[i][j];
if (digit[i] == 4 || (digit[i] == 2 && digit[i + 1] == 6))
break;
}
return ans;
}
int main()
{
int m, n;
init();
while (cin >> n >> m && (n + m))
cout << solve(m + 1) - solve(n) << "\n";
//solve()没有对n本身进行判断，算的是[1,n)的情况，所以要+1
return 0;
}