SHARE
TWEET

codeforce - lucky sum

jakaria_hossain Jun 16th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fast()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. #define pb push_back
  5. #define ll long long
  6. #define MAX 4444444445
  7. int main()
  8. {
  9.     fast()
  10.     vector<ll>v;
  11.     v.pb(4);
  12.     v.pb(7);
  13.     for(int i=0;i<v.size();i++)
  14.     {
  15.         if(v[i]*10+4>MAX)break;
  16.         else v.pb(v[i]*10+4);
  17.         if(v[i]*10+7>MAX)break;
  18.         else v.pb(v[i]*10+7);
  19.     }
  20.     ll sum=0,l,r;
  21.     cin>>l>>r;
  22.     while(l<=r)
  23.     {
  24.         ll pos=lower_bound(v.begin(),v.end(),l )- v.begin();
  25.         if(v[pos]>r)sum+=(r-l+1)*v[pos];
  26.         else sum+=(v[pos]-l+1)*v[pos];
  27.         l=v[pos]+1;
  28.     }
  29.     cout<<sum<<endl;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top