(File IO): input: sum.in output: sum.out
time limit: 1000 ms space constraints: 131072 KB specific restrictions
Goto ProblemSet
Title Description
and
is a lucky number flavor taste. Lucky number is a positive integer of only those lucky numbers. ¥ 47,4774 is as lucky number, and
is not a lucky number.
definition
is greater than or equal to
minimum number of lucky.
Taste taste very interested in the value of the expression:
Now tell you the value of L and R, and I hope you can help flavor taste calculated value of the expression.
Enter the
input file
only line containing two positive integers and L
,
and
separated by a space between the values.
Output
Output file
only one line an integer representing the value of the expression.
Sample input
[1] Input Sample
27
Sample input [2]
77
Sample output
[output 1] Sample
33
[2] Output Sample
7
Data range limits
for
% of the data,
For
% of the data,
Another
% of the data,
for
% of the data,
Tips
[description] Sample 1
[description] Sample 2
Problem-solving ideas
first dfs a lucky number, (because dfs is sequentially stored lucky number, so no need to sort it again). Then simulation.
Code
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
long long l,r,ans,t,s,t1,x,ii;
long long d[5000];
void dfs(long long x,long long y)
{
if(x==1)
{
d[++t1]=y;
return;
}
dfs(x-1,y*10+4);
dfs(x-1,y*10+7);
}
int main()
{
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
scanf("%lld%lld",&l,&r);
for(int i=1; i<=12; i++)
dfs(i,0);
t=1,ii=l;
while(l>d[t])
t++;
while(ii<=r)
{
x=min(d[t]-ii,r-ii)+1;
s+=d[t]*x;
ii+=x;
t++;
}
printf("%lld",s);
return 0;
}