#include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include < stack> #include <queue> #include <set> #include <map> #include <vector> #include <cmath > #include <cstring>using namespace Std;int Dp[10][3];//dp[i][j] represents the number of digits, J for status//dp[i][0] means there is no unlucky number//dp[i][ 1] Indicates that there is no Geely number, and the highest level is 2//dp[i][2] indicates the presence of an unlucky number void init () {memset (dp,0,sizeof (DP));DP [0][0] = 1;//Initializes a 0-bit unlucky number of 1for (int i = 1 , I <= 7;i++) {dp[i][0] = dp[i-1][0]*9-dp[i-1][1];//The highest bit does not contain 4 9 digits, and because when I place 6, i-1 can not put 2, so subtract the i-1 bit does not exist unlucky number cut the highest bit 2 Situation dp[i][1] = dp[i-1][0];//highest bit put 2 other bits as long as not unlucky numbers can dp[i][2] = dp[i-1][2] * +dp[i-1][0] + dp[i-1][1];// I-bit contains the number of unlucky number is i-1 bit of X10, because as long as there are unlucky numbers in front of whatever can be so the front x10, in addition if the highest bit put a 4 and then all is not unlucky number on the line, can also be the highest bit put on a 6 then, The second-to-last 2 is not unlucky.}}int Fun (int n) {int len = 0,tem = N,ans,flag,a[10];while (n) {A[++len] = N%10;n/= 10;} A[len+1] = ans = 0;flag = 0;//Find an unlucky number between (n-1) for (int i = Len;i >= 1;i--) {ans + = dp[i-1][2] * a[i];//behind I-1 is unluckyThe number can then be filled with any if (flag) {ans + = dp[i-1][0] * a[i];} if (!flag && a[i] > 4) {ans + = dp[i-1][0];//If a[i]>4 then you can put a 4}if on the I bit (!flag && a[i+1] = = 6 && A[i] > 2) {//If the latter is 6 this bit is greater than 2 ans + = dp[i][1];} if (!flag && a[i] > 6) {ans + = dp[i-1][1];} if (a[i] = = 4 | | a[i+1] = = 6 && a[i] = = 2) {flag = 1;}} return Tem-ans;} int main () {int n,m;init (); while (CIN >> n >> m,n| | m) {printf ("%d\n", Fun (m+1)-Fun (n));} return 0;}
HDU 2089 do not 62-digit DP