Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string>
- #include <string.h>
- #include <vector>
- #include <queue>
- #include <set>
- #include <stack>
- #include <algorithm>
- #define FOR(A, B) for(A=0;A<B;A++)
- #define MAXN 111
- using namespace std;
- long long l,r;
- vector<long long> luckies;
- void gen(long long x)
- {
- if(x <= 15LL*r && x > 0) {
- //printf("%lld\n", x);
- luckies.push_back(x);
- }
- if(x > r) return;
- gen(x*10LL+4LL);
- gen(x*10LL+7LL);
- }
- int main()
- {
- int i,j,k,m;
- int ll,rr;
- scanf("%d %d", &ll, &rr);
- l = (long long)ll; r = (long long)rr;
- gen(0);
- sort(luckies.begin(), luckies.end());
- i = 0;
- while(luckies[i] < l) i++;
- long long ans = (min(luckies[i], r)-l+1)*luckies[i];
- long long prev = luckies[i]+1;
- for(j = i+1; j < luckies.size(); j++) {
- if(prev > r) break;
- ans += (min(luckies[j], r)-prev+1)*(long long)luckies[j];
- prev = luckies[j]+1;
- }
- printf("%I64d\n", ans);
- return 0;
- }
Add Comment
Please, Sign In to add comment