# 不要62

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 52666    Accepted Submission(s): 20065

Problem Description

62315 73418 88914

Input

Output

Sample Input
1 1000 0

Sample Output
80

Author
qianneng

Source

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int s[1000010];

int main()
{
int a, b, num[10], sum;
sum = 0;
s[0] = 1;
for(int i = 1; i <= 1000000; i ++) {
if(i%10 == 4 || i/10%10 == 4 || i/100%10 == 4 || i/1000%10 == 4 || i/10000%10 == 4 || i/100000%10 == 4) {
s[i] = s[i-1];continue;
}
if(i%100 == 62 || i/10%100 == 62 || i/100%100 == 62 || i/1000%100 == 62 || i/10000%100 == 62) {
s[i] = s[i-1];continue;
}
s[i] = s[i-1]+1;
}
while(~scanf("%d%d", &a, &b)) {
if(a == 0 || b == 0) break;
printf("%d\n", s[b] - s[a]);
}
return 0;
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>

using namespace std;

int sum[1000010], a, b;
char str[1000010];

int main()
{
sum[0] = 1;
for(int i = 1; i <= 1000000; i++) {
itoa(i, str, 10); //把i转化为10进制的数再转化为字符串
if(strstr(str, "4") == NULL && strstr(str, "62") == NULL) { //判断是否为子串
sum[i] = sum[i-1] + 1;
continue;
}
sum[i] = sum[i-1];
}
while(~scanf("%d%d", &a, &b)) {
if(a == 0 || b == 0) break;
printf("%d\n", sum[b] - sum[a-1]);
}
return 0;
}

isoa函数的介绍 （点击可查看，与sprintf函数作用差不多，但是有进制转化的功能）
strstr函数的介绍 （比较两个字符串是否有字串关系）

dp大法：数位dp法（0ms，在线解决，对于数据非常大的同样适用）
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>

using namespace std;

int num[10], a, b, k;
int dp[10][2];

int dfs(int len, bool is6, bool limet)
{
if(len == 0)
return 1;
if(!limet && dp[len][is6]) {
return dp[len][is6];
}
int cnt = 0;
int maxx = (limet ? num[len] : 9);
for(int i = 0; i <= maxx;  i++) {
if((i == 2 && is6) || i == 4) //条件判断
continue;
if(i == 6)
cnt += dfs(len - 1, true, limet && i == maxx);
else cnt += dfs(len - 1, false, limet && i == maxx);
}
return limet ? cnt : dp[len][is6] = cnt;
}

int solve(int n)
{
memset(num, 0, sizeof(num));
memset(dp, 0, sizeof(dp));
k = 0;
while(n > 0) {
num[++ k]  = n%10; //使用k ++时注意dfs中的k要-1，并且初始化为1
n /= 10;
}
dfs(k, false, true);
}

int main()
{
while(~scanf("%d %d", &a, &b)) {
if(a == 0 || b == 0) break;
printf("%d\n", solve(b) - solve(a-1));
}
return 0;
}