幸运数字的定义是这样:仅含4和7且不比n小的数为n的幸运数字。

输入范围l,r要求输出这个范围内的数字的幸运数字之和。

代码:

 #include<stdio.h>
#define N 1024
typedef long long ll;
ll a[N+];
ll f(ll n)
{
if(n==)
return ;
int i;
ll ans=;
for(i=;i<=N;i++)
{
if(a[i]<n)
ans+=a[i]*(a[i]-a[i-]);
else{
ans+=a[i]*(n-a[i-]);
break;
}
}
return ans;
}
int main(void)
{
int l,r,i;
scanf("%d%d",&l,&r);
a[]=,a[]=;
int t=;
for(i=;i<=;i++)
{
a[t++]=a[i]*+;
a[t++]=a[i]*+;
}
printf("%I64d\n",f(r)-f(l-));
return ;
}

其实可以先把10^10以内的幸运数字存进数组,然后分别计算l-1,r,以内的数字的幸运数字的和,两者相减即为最终结果。

CF_Lucky Sum的更多相关文章

  1. LeetCode - Two Sum

    Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summa ...

  2. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  3. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  4. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  5. BZOJ 3944 Sum

    题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不 ...

  6. [LeetCode] Path Sum III 二叉树的路径和之三

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  7. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  8. [LeetCode] Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  9. [LeetCode] Sum of Left Leaves 左子叶之和

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

随机推荐

  1. hihocoder 第一周 最长回文字串

    题目1 : 最长回文子串 时间限制:1000ms 单点时限:1000ms 内存限制:64MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程 ...

  2. IE6下Png透明最佳解决方案(推荐) Unit PNG Fix

    引自:http://www.yeeyan.org/articles/view/98510/67784 网络上解决IE6下Png透明解决方案有很多,例如 IE PNG Fix from TwinHeli ...

  3. jBPM5 vs Actitivi

    http://www.blogways.net/blog/2013/07/16/activiti-jbpm-compare.html jBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baey ...

  4. Asp.net自制模板框架

    最近在做个包含了大量重复样式的控件的网站. 如果用MVC的话,我可以针对每个需要单独块编辑的Model写一个局部视图. 然后根据不同逻辑需求拼起来.用现成MVC框架非常容易做到. 但环境是3.5的最高 ...

  5. EditText属性详解

    关于EditText属性详解很详细的记录,转过来收着 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password=" ...

  6. MVC小系列(八)【改变Areas的FindView顺序】

    MVC小系列(八)[改变Areas的FindView顺序] 一般项目比较大的话,会根据模块建立Areas,这样结构清晰,也有利于路由的部署, 1 Areas下有自己的_LayOut模板,而如果希望所有 ...

  7. OC - 9.使用Quartz2D绘制下载进度条

    效果图 实现思路 要实现绘图,通常需要自定义一个UIView的子类,重写父类的- (void)drawRect:(CGRect)rect方法,在该方法中实现绘图操作 若想显示下载进度,只需要实例化自定 ...

  8. stm32中.bss和.data段是在哪里初始化的

    https://segmentfault.com/q/1010000004829859/a-1020000004850311 Q: STM32的启动文件startup_stm32f10x_hd.s中的 ...

  9. 销毁session

    session运行在服务器是单用户,每个session都有一个唯一的sessionid 用法:session.setAttribute("userName", "张三丰& ...

  10. wap开发笔记之幻灯片

    最近在进行wap站研究,发现网上成熟的wap幻灯片都很难找到,在此贴出一个iphone的幻灯效果,希望对wap站开发的人有些帮助. 点此下载