题目链接:https://ac.nowcoder.com/acm/contest/5086/E
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 int l,r,cnt,a[10005]; 5 void dfs(int x) 6 { 7 if(x>1000000000)return; 8 a[++cnt]=x; 9 dfs(x*10+4); 10 dfs(x*10+7); 11 } 12 signed main() 13 { 14 dfs(4); 15 dfs(7); 16 a[++cnt]=4444444444; 17 sort(a+1,a+cnt+1); 18 scanf("%lld%lld",&l,&r); 19 int ans=0; 20 for(int i=1;i<=cnt;i++) 21 if(a[i]>=l) 22 { 23 if(a[i]>=r){ans+=a[i]*(r-l+1);break;} 24 else{ans+=a[i]*(a[i]-l+1);l=a[i]+1;} 25 } 26 cout<<ans; 27 return 0; 28 }