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
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; typedef long long LL; inline const LL Get_Int() { LL num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } LL x,y,f[15][15][2],a[15],cnt=0; LL Dp(int Now,int last,bool up) { if(Now>cnt)return 1; if(~f[Now][last][up])return f[Now][last][up]; f[Now][last][up]=0; int limit=up?a[Now]:9; for(int i=0; i<=limit; i++) { if(i==4)continue; if(!(last==3&&i==7))f[Now][last][up]+=Dp(Now+1,i,up&&i==limit); } return f[Now][last][up]; } LL Solve(LL x) { cnt=0; while(x) { a[++cnt]=x%10; x/=10; } memset(f,-1,sizeof(f)); reverse(a+1,a+cnt+1); return Dp(1,0,1); } int main() { x=Get_Int(); y=Get_Int(); printf("%lld\n",Solve(y)-Solve(x-1)); return 0; }
|