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 49 50 51 52 53
|
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=20; long long f[N][15][15][2][2][2][2][2]; int n,l[N]; long long dfs(int to,int last1,int last2,bool limit,bool zero,bool four,bool eight,bool ok) { if(f[to][last1][last2][limit][zero][four][eight][ok]>=0) return f[to][last1][last2][limit][zero][four][eight][ok]; long long t_ans=0; if(to==n+1) { if((four and eight)==false and ok==true) t_ans=1; return f[to][last1][last2][limit][zero][four][eight][ok]=t_ans; } for(int i=0;i<=(limit==true?l[to]:9);i++) { if(zero==false or i!=0) t_ans+=dfs(to+1,i,last1,limit==true and i==l[to],false,four or i==4,eight or i==8,ok==true or(last1==last2 and last2==i)); else t_ans+=dfs(to+1,i,last1,limit==true and i==l[to],true,false,false,false); } return f[to][last1][last2][limit][zero][four][eight][ok]=t_ans; } int main() { long long ans[3]; for(int i=1;i<=2;i++) { long long t_num; scanf("%lld",&t_num); if(i==1) t_num--; n=0; while(t_num!=0) l[++n]=t_num%10,t_num/=10; reverse(l+1,l+1+n);
memset(f,0x80,sizeof f); dfs(1,0,0,true,true,false,false,false);
ans[i]=f[1][0][0][true][true][false][false][false]; }
printf("%lld",ans[2]-ans[1]); return 0; }
|