Advertisement
leminhkt

83

Oct 23rd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6.         /* ------- declaration ------- */
  7.  
  8.     long long l, r;
  9.     long long cr, ans;
  10.  
  11.  
  12.     long long calc(int n) {
  13.         long long base = 1;
  14.         long long res = 0;
  15.         do {
  16.             if (n&1)
  17.                 res += 7*base;
  18.             else
  19.                 res += 4*base;
  20.             n >>= 1, base *= 10;
  21.         }
  22.         while (n > 1);
  23.         return res;
  24.     }
  25.  
  26. /* ------- ~~~~~~~~~~~ ------- */
  27.  
  28.  
  29.  
  30.         /* ----------------- main func ----------------- */
  31.  
  32.     void query() {
  33.         cin >> l >> r;
  34.  
  35.  
  36.         for (int i = 2; true; ++i) {
  37.             cr = calc(i);
  38.             if (cr > r) break;
  39.             if (cr >= l)
  40.                 ans += (cr - l + 1)*cr,
  41.                 l = cr + 1;
  42.         }
  43.         ans += (r - l + 1)*cr;
  44.  
  45.  
  46.         cout << ans;
  47.     }
  48.  
  49. /* ----------------- ~~~~~~~~~ ----------------- */
  50.  
  51.  
  52.  
  53. int main(){
  54.     //freopen("Test.INP", "r", stdin);
  55.     //freopen("Test.OUT", "w", stdout);
  56.     cin.tie(NULL)->sync_with_stdio(false);
  57.  
  58.         /* ------- setup ------- */
  59.  
  60.     srand(time(0));
  61.     cout << fixed << setprecision(2);
  62.     int t = 1; for (; t--; query());
  63.  
  64. /* ------- ~~~~~ ------- */
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement