Guest User

Untitled

a guest
Feb 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1.     #include <cstdio>
  2.     #include <iostream>
  3.  
  4.     using namespace std;
  5.  
  6.     typedef long long int64;
  7.  
  8.     int64 new_lucky(int64 a, int64 n) {
  9.       int64 ans = 0;
  10.       int64 cur = 1;
  11.       do {
  12.         if (a % 2) {
  13.           ans += 7 * cur;
  14.         } else {
  15.           ans += 4 * cur;
  16.         }
  17.         a /= 2;
  18.         cur *= 10;
  19.         n--;
  20.       } while (n);
  21.       return ans;
  22.     }
  23.  
  24.     int main() {
  25.       int a, b;
  26.       scanf("%d%d", &a, &b);
  27.       int64 ans = 0;
  28.       int64 c = 0, d = 1, e = 2;
  29.       int64 cur = -1;
  30.       for ( ; ; ) {
  31.         int64 g = new_lucky(c, d);
  32.         c++;
  33.         if (c == e) {
  34.           c = 0;
  35.           d++;
  36.           e *= 2;
  37.         }
  38.         if (g >= a) {
  39.           if (g >= b) {
  40.             ans += g * (cur == -1 ? b - a + 1 : b - cur);
  41.             break;
  42.           } else {
  43.             ans += g * (cur == -1 ? g - a + 1 : g - cur);
  44.             cur = g;
  45.           }
  46.         }
  47.       }
  48.       cout << ans << endl;
  49.       return 0;
  50.     }
Add Comment
Please, Sign In to add comment