You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
751 B
35 lines
751 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 32;
|
|
|
|
int a[N], al;
|
|
int f[N][10];
|
|
|
|
int dfs(int u, int st, bool op) {
|
|
if (u == 0) return 1;
|
|
if (!op && ~f[u][st]) return f[u][st];
|
|
int up = op ? a[u] : 9;
|
|
int ans = 0;
|
|
for (int i = 0; i <= up; i++) {
|
|
if (st == 6 && i == 2) continue;
|
|
if (i == 4) continue;
|
|
ans += dfs(u - 1, i, op && i == a[u]);
|
|
}
|
|
|
|
if (!op) f[u][st] = ans;
|
|
return ans;
|
|
}
|
|
|
|
int calc(int x) {
|
|
al = 0;
|
|
while (x) a[++al] = x % 10, x /= 10;
|
|
return dfs(al, -1, true);
|
|
}
|
|
int main() {
|
|
memset(f, -1, sizeof f);
|
|
int l, r;
|
|
while (~scanf("%d%d", &l, &r) && l + r)
|
|
printf("%d\n", calc(r) - calc(l - 1));
|
|
return 0;
|
|
} |