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 44 45 46 47 48
| #include <bits/stdc++.h>
using namespace std;
int dp[10][10][2], digits[10];
int dfs(int pos, int pre, int status, int limit) { if(pos < 1) return status; if(!limit && dp[pos][pre][status] != -1) return dp[pos][pre][status]; register int end = limit ? digits[pos] : 9, ret = 0; for(register int i = 0; i <= end; i++) ret += dfs(pos - 1, i, status || (pre == 6 && i == 2) || i == 4, limit && (i == end)); if(!limit) dp[pos][pre][status] = ret;
return ret; }
inline int solve(int x) { register int len = 0; while(x) { digits[++len] = x % 10; x /= 10; } return dfs(len, 0, 0, 1); }
int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(NULL); memset(dp, -1, sizeof(dp)); int a, b; cin >> a >> b; register int ans = solve(b); memset(dp, -1, sizeof(dp)); cout << b - (ans - solve(a - 1)) - a + 1; return 0; }
|