Lucky Sum

Time Limit: 2000ms
Memory Limit: 262144KB

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

Input
2 7
Output
33
Input
7 7
Output
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

 
解题:只包含4或者7的数字很少的。搜一遍就是了。
 
 #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",&lt,&rt))
printf("%I64d\n",sum(rt)-sum(lt-));
return ;
}

Codeforces 121A Lucky Sum的更多相关文章

  1. Lucky Sum

    Description Lucky Sum time limit per test: 2 seconds memory limit per test: 256 megabytes input: sta ...

  2. Codeforces 396B On Sum of Fractions 数论

    题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...

  3. codeforces 963A Alternating Sum

    codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) ...

  4. codeforces 1217E E. Sum Queries? (线段树

    codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...

  5. CodeForces 146A Lucky Ticket

    Lucky Ticket Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  6. 『题解』Codeforces121A Lucky Sum

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Petya loves lucky numbers. Everybody k ...

  7. Codeforces 577B Modulo Sum

    http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神 ...

  8. Codeforces 85 D. Sum of Medians

    题目链接:http://codeforces.com/contest/85/problem/D 做法果然男默女泪啊..... 大概就是直接开了一个$vector$每次插入删除都用自带的$insert$ ...

  9. Codeforces 797B - Odd sum

    B. Odd sum 题目链接:http://codeforces.com/problemset/problem/797/B time limit per test 1 second memory l ...

随机推荐

  1. 命令搜索命令(whereis、which)

    一.whereis命名 解释:搜索系统命令所在的位置,不能查询文件 语法:whereis 命令 -b  之查找可执行的文件在哪里 -m 只查找帮助文件 二.which 命令 解释:能搜索命令所在位置, ...

  2. 基于PHP自带的mail函数实现发送邮件以及带有附件的邮件功能

    PHPmail函数简介 bool mail ( string $to , string $subject , string $message [, string $additional_headers ...

  3. 如何过滤 adb logcat 输出(转载)

    转自:http://www.cnblogs.com/imouto/archive/2012/12/11/filtering-adb-logcat-output.html 简介: 本文介绍如何在 she ...

  4. E20170606-gg

    complete adj. 完整的; 完成的; (用以强调) 完全的; 达到结尾的;  vt. 完成,使完满; 完成或结束; 填写(表格); process   n. 过程; 工序; 做事方法; 工艺 ...

  5. HTML5来了,7个混合式移动开发框架

    在这个时间开始学习移动开发真是最好不过了,每个人应该都有一些移动应用的创意,而且你并不需要任何的原生应用编程经验,你只需要一些HTML的相关知识,懂一些CSS和JavaScript就够了.如果你总听别 ...

  6. robotframework - 基础关键词

    robotframework基础关键词如下: 1.可在python.notepad++ 编辑: *** Settings *** *** Test Cases ***variable ${a} Set ...

  7. vue用户登录状态判断

    之前项目中用来判断是否登录我写了多种方案,但是最终只有一个方案是比较好的,这篇博客就是分享该方案; 先说基本要求: 项目中的登录状态是依据服务器里的状态来作为判断依据; 每一个需要登录后才能操作的接口 ...

  8. mvn 配置

    <!-- 阿里云仓库1 -->    <mirror>        <id>alimaven-1</id>        <name>al ...

  9. [W3School]JavaScript教程学习

    JavaScript 简介 JavaScript 是世界上最流行的编程语言.这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备. JavaScript ...

  10. [转]windows 7 下快速搭建php环境(windows7+IIS7+php+mysql)

    转贴:http://apps.hi.baidu.com/share/detail/10406992 (1).采用理由: 优点:最大化的桌面图形化操作系统,可维护性优秀.基于IIS v6.0/v7.0( ...