-
-
Save MinecraftFuns/7cb99fc1f7a3d49d276150e631e1cae6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constexpr int DIGIT = 20; | |
int a[DIGIT]; | |
int dp[DIGIT][2]; | |
int dfs(int pos, int pre, bool status, bool limit) | |
{ | |
if (pos == -1) | |
{ | |
return 1; | |
} | |
if (!limit && dp[pos][status] != -1) | |
{ | |
return dp[pos][status]; | |
} | |
int _cac = limit ? a[pos] : 9; | |
int res = 0; | |
for (int i = 0; i <= _cac; i++) | |
{ | |
if ((pre != 6 || i != 2) && i != 4) | |
{ | |
res += dfs(pos - 1, i, i == 6, limit && i == a[pos]); | |
} | |
} | |
if (!limit) | |
{ | |
dp[pos][status] = res; | |
} | |
return res; | |
} | |
inline int solve(int x) | |
{ | |
int pos = 0; | |
while (x) | |
{ | |
a[pos++] = x % 10; | |
x /= 10; | |
} | |
return dfs(pos - 1, -1, 0, 1); | |
} | |
int l, r; | |
int main() | |
{ | |
while (~scanf("%d %d", &l, &r) && (l != 0 || r != 0)) | |
{ | |
memset(dp, -1, sizeof(dp)); | |
printf("%d\n", solve(r) - solve(l - 1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment