-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdu2089.cpp
More file actions
43 lines (37 loc) · 861 Bytes
/
hdu2089.cpp
File metadata and controls
43 lines (37 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstdio>
#include <cstring>
typedef long long LL;
LL num[15];
LL dodfs(int len, bool preSix, bool limitR) {
if(len == 0) return 1;
LL result = 0;
int limit = limitR?num[len]:9;
for(int i = 0; i <= limit; ++i) {
if(preSix && i == 2 || i == 4) continue;
result += dodfs(len-1, i == 6, limitR&&i==limit);
}
return result;
}
int count_digit(LL n) {
memset(num, 0, sizeof(num));
int len = 1;
while(n > 0) {
num[len++] = n % 10;
n /= 10;
}
return len - 1;
}
LL solve(LL n) {
if(n == -1) return 0;
int count = count_digit(n);
return dodfs(count, false, true);
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
LL start, end;
while(scanf("%lld%lld", &start, &end) != EOF && (start || end)) {
printf("%lld\n", solve(end) - solve(start-1));
}
return 0;
}