Description
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers, 744, 4 are lucky and 5, 467.
Let next (x) are the minimum lucky number which is larger than or equals X. Petya is interested what is the value of the EXP Ression Next (L) + next (L + 1) + ... + next (r-1) + next (R). Help him solve this problem.
Input
The single line contains two integers l and R (1≤l≤r≤10^9)-the left and right interval limits.
Output
In the "single" Print the only number-the sum next (L) + next (L + 1) + ... + next (r-1) + next (R).
Please don't use the%LLD specificator to read or write 64-bit integers in C + +. It is preferred to use the CIN, cout streams or the%i64d specificator.
examples Input
2 7
examples Output
33
the
We define last (i) last (i) to represent the lucky number with the smallest greater than or equal to I, seeking ∑ri=llast (i) \sum_{i=l}^rlast (i).
train of Thought
It's clear that chunking works, so we just need to write a few lucky numbers that look for a number.
AC Code
#include <bits/stdc++.h> #define IO Ios::sync_with_stdio (false); \ cin.tie (0); \ cout.tie (0);
using namespace Std;
typedef long Long LL;
const int MAXN = 1E5+10; ll last (ll x) {int len = int (log10 (x)) + 1;
Number digits LL ans = 0,cnt = 0;
for (int i=0; i<len; i++)//equal digits maximum minimum lucky number ans = ans*10+4,cnt = cnt*10+7;
if (x>cnt)//bit number +1 return ans*10+4;
while (ans<x) {LL res = CNT;
for (int i=0; i<1<<len; i++) {LL tmp = 0;
for (int j=0; j<len; J + +) {if (i& (1<<j)) tmp = TMP*10+7;
else tmp = tmp*10+4;
if (tmp>=x) res = min (res,tmp);
ans = res;
return ans;
int main () {LL l,r;
cin>>l>>r;
LL now = L,ans = 0;
while (true) the {LL La = last (now); IfLa>r) {ans+= la * (r-now+1);
Break
else ans = la * (la-now+1);
now = la+1;
} cout<<ans<<endl;
return 0; }