CodeForces
来源:互联网 发布:云计算板块平均市盈率 编辑:程序博客网 时间:2024/06/05 18:01
Lucky Sum
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 47, 744, 4 are lucky and 5, 17, 467 are not.
Let next(x) be the minimum lucky number which is larger than or equals x. Petya is interested what is the value of the expression 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 ≤ 109) — the left and right interval limits.
Output
In the single line print the only number — the sum next(l) + next(l + 1) + ... + next(r - 1) + next(r).
Example
Input2 7Output33Input7 7Output7
Note
In the first sample: next(2) + next(3) + next(4) + next(5) + next(6) + next(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33In the second sample: next(7) = 7
next数组可以打表(打大一点),稍微优化一下就能过。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define N 2222#define ll long longll a[N];int ans = 0;void init( ll num ){ if( num >= 1e10 ) return ;/// mx > 1e9 else a[ans++] = num; init( num * 10 + 4 ); init( num * 10 + 7 );}int main(){ freopen( "in.txt", "r", stdin ); init( 0 ); sort( a, a + ans );//for( int i = 0 ; i < 1023 ; i ++ )cout<<a[i]<<" "; int n, m, l, r, mid; ll sum; while( scanf( "%d%d", &n, &m ) != EOF ){ ///还想用二分的,但是好像不适用。// l = 1, r = ans-1;// while( l <= r ){// mid = (l + r) / 2;// if( a[mid] > n )// r = mid - 1;// else if( a[mid] < n )// l = mid + 1;// else break;// } if( n < 1 && m < 1 ) break; l = 0, r = 0; for( int i = 1; i < ans ; i ++ ){ if( a[i] >= n && l == 0 ) l = i; if( a[i] >= m && r == 0 ) r = i; if( l && r ) break; } sum = 0; if( l == r ){ for( int i = n ; i <= m ; i ++ ){ sum += a[l]; } } else{ sum += ( a[l] - n + 1 ) * a[l];/// +1 for( int i = l+1 ; i <= ans ; i ++ ){ if( a[i] >= m ){ sum += ( m - a[i-1] ) * a[i]; break; } else{ sum += ( a[i] - a[i-1] ) * a[i]; } } } cout<<sum<<endl; } return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Python 列表(List)
- JAVA设计模式(四)----原型模式
- python robotframework用法及"wxpython not found"和“no browser is open”问题解决
- ORACLE 定时清理归档日志详细过程
- AndroidStudio中使用Git-高级篇(二)——新建分支和拉取请求(by 星空武哥)
- CodeForces
- runtime从入门到精通(二)—— 官方文档翻译
- android studio 运行中的一些小错误解决办法(持续更新中······)
- 配置yum源从镜像SO文件
- SCM+MLC/TLC NAND混合SSD性能探究
- java web面试技巧,数据库面试,java web轻量级开发面试教程
- npm镜像切换大法
- Linux基础练习一
- 神经网络中的激活函数-Sigmoid, ReLu, TanHyperbolic(tanh), softmax, softplus简述