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 ...
随机推荐
- bzoj 1827: [Usaco2010 Mar]gather 奶牛大集会【树形dp】
不能用read会TLE!!不能用read会TLE!!不能用read会TLE!! 一开始以为要维护每个点,线段树写了好长(还T了-- 首先dfs一遍,求出点1为集会地点的答案,处理处val[u]为以1为 ...
- 引水入城 2010年NOIP全国联赛提高组(bfs+贪心)
1066 引水入城 2010年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在一个遥远 ...
- Selct 大全
添加option $("#ID option").each(function(){ if($(this).val()==111){ $(this).remove(); } }); ...
- Androidstudio的安装与使用调试
1安装与基本使用 1.1androidstudio的安装 1.到android-studio\bin文件夹里面,根据自己的电脑配置,打开studio.exe或者studio64.exe 2.按照向导默 ...
- NodeJs学习记录(二)win7下 配置node连接oracle的环境
2017/01/23 星期一 前言:还没看几眼教程,就开始分配任务,涉及到连oracle数据库,所以顺便把整个环境的配置放上来 安装文件清单(1).node-v6.9.1-x64.msi(2).pyt ...
- javascirpt中的数字在计算机内存储为多少Byte
JavaScript内部,所有数字都是以64位浮点数形式储存,即使整数也是如此 8 Byte = 64bit Javascript中,由于其变量内容不同,变量被分为基本数据类型变量和引用数据类型变量. ...
- Pro ASP.NET Core MVC 第6版 第二章(后半章)
增加动态输出 整个web应用平台的关注点在于构建并显示动态输出内容.在MVC里,控制器负责构建一些数据并将其传给视图.视图负责渲染成HTML. 从控制器向视图传递数据的一种方式是使用ViewBag 对 ...
- MySQL详解(18)-----------分页方法总结
---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适应场景: 适用于数据量较少的情况(元组百/千 ...
- PHP——基本使用(二)
PHP与Apache Apache服务器在接受到客户端请求的时候,根据客户端所请求的文件的类型,然后去问模块能否处理此文件,php作为模块之一有可能可以处理此文件,处理之后将数据再返回给apache, ...
- PHP 在表单POST提交后数据分页实现,非GET,解决只有第一页显示正确的问题
//PHP 在表单POST提交后数据分页实现,非GET,使用SESSION,分页代码部分不在详述,主要为POST后的 除第一页之外的显示问题 //以下为ACTION页面 内容,仅为事例,当判断到页面未 ...