Codeforces 121A Lucky Sum
Lucky Sum
This problem will be judged on CodeForces. Original ID: 121A
64-bit integer IO format: %I64d Java class name: (Any)
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).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64dspecificator.
Sample Input
2 7
33
7 7
7
Hint
In the first sample: next(2) + next(3) + next(4) + next(5) + next(6) + next(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: next(7) = 7
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
LL d[maxn];
int tot = ;
void dfs(LL num,int cur) {
d[tot++] = num;
if(cur > ) return;
dfs(num*+,cur+);
dfs(num*+,cur+);
}
LL sum(LL x) {
if(x == ) return ;
LL temp = ;
for(int i = ; i < tot; i++) {
if(x >= d[i])
temp += d[i]*(d[i]-d[i-]);
else {
temp += d[i]*(x-d[i-]);
break;
}
}
return temp;
}
int main() {
dfs(,);
dfs(,);
sort(d+,d+tot);
LL lt,rt;
while(~scanf("%I64d %I64d",<,&rt))
printf("%I64d\n",sum(rt)-sum(lt-));
return ;
}
Codeforces 121A Lucky Sum的更多相关文章
- Lucky Sum
Description Lucky Sum time limit per test: 2 seconds memory limit per test: 256 megabytes input: sta ...
- Codeforces 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
- codeforces 963A Alternating Sum
codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) ...
- codeforces 1217E E. Sum Queries? (线段树
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...
- CodeForces 146A Lucky Ticket
Lucky Ticket Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- 『题解』Codeforces121A Lucky Sum
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Petya loves lucky numbers. Everybody k ...
- Codeforces 577B Modulo Sum
http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神 ...
- Codeforces 85 D. Sum of Medians
题目链接:http://codeforces.com/contest/85/problem/D 做法果然男默女泪啊..... 大概就是直接开了一个$vector$每次插入删除都用自带的$insert$ ...
- Codeforces 797B - Odd sum
B. Odd sum 题目链接:http://codeforces.com/problemset/problem/797/B time limit per test 1 second memory l ...
随机推荐
- 人脸识别(初学篇)-VS2015+opencv3.2的配置
初学人脸识别,感觉安装也是一个很大的麻烦. 写在这里记录一下吧 一:先安装好我们需要的软件 首先安装Vs2015,在官网或者csdn搜一下应该找的到. 安装步骤没有太多讲究. 点击exe文件,我选择的 ...
- org.apache.poi.hssf.util.Region
从POI 3.18开始被Deprecated,在3.20版本中被移除了,所以3.20以前的都有 为了避免这个问题,用CellRangeAddress代替Region,其用法相同
- 修复mysql的表
数据损坏原因 MySQL表损坏一般是数据损坏,引起损坏的原因可能是由于磁盘损坏.系统崩溃或者MySQL服务器被崩溃等外部原因.例如有人使用kill -9终止进程,导致MySQL进程未能正常关闭,那么就 ...
- [HAOI2006]均分数据
题解 今天下午刚学了模拟退火 借这个题来总结下模拟退火的要注意的问题吧 1 : \(eps\)不要设的太大 2 : 初温\(T\)在2000左右就差不多可以了 3 : 注意题目要求是要求最大值还是最小 ...
- 全面学习ORACLE Scheduler特性(2)管理jobs
1.2 管理Jobs 1.2.1 启用Jobs 前面创建JOB时,由于未显式的指定ENABLED参数,因此即使指定了START_DATE,不过默认情况下JOB不会自动执行.对于这种情况,DBMS_ ...
- dubbo与zookeeper学习中的问题
环境: spring5.1.5 dubbo 2.6.2 异常信息: java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy at ...
- Python之pandas数据加载、存储
Python之pandas数据加载.存储 0. 输入与输出大致可分为三类: 0.1 读取文本文件和其他更好效的磁盘存储格式 2.2 使用数据库中的数据 0.3 利用Web API操作网络资源 1. 读 ...
- 短URL生成
算法原理 算法一 1)将长网址md5生成32位签名串,分为4段, 每段8个字节; 2)对这四段循环处理, 取8个字节, 将他看成16进制串与0x3fffffff(30位1)与操作, 即超过30位的忽略 ...
- Android基础TOP6_2:Gallery +Image完成画廊
Activity: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- [Windows Server 2012] 初识Windows Server 2012
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:初次见识Win ...