Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- using namespace std;
- typedef long long int64;
- int64 new_lucky(int64 a, int64 n) {
- int64 ans = 0;
- int64 cur = 1;
- do {
- if (a % 2) {
- ans += 7 * cur;
- } else {
- ans += 4 * cur;
- }
- a /= 2;
- cur *= 10;
- n--;
- } while (n);
- return ans;
- }
- int main() {
- int a, b;
- scanf("%d%d", &a, &b);
- int64 ans = 0;
- int64 c = 0, d = 1, e = 2;
- int64 cur = -1;
- for ( ; ; ) {
- int64 g = new_lucky(c, d);
- c++;
- if (c == e) {
- c = 0;
- d++;
- e *= 2;
- }
- if (g >= a) {
- if (g >= b) {
- ans += g * (cur == -1 ? b - a + 1 : b - cur);
- break;
- } else {
- ans += g * (cur == -1 ? g - a + 1 : g - cur);
- cur = g;
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment