幸运数字的定义是这样:仅含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. freewrap——将tcl/tk脚本转变为可执行文件

     FreeWrap可以把TCL/TK的脚本和二进制文件打包成应用程序,FreeWrap将所有的文件组合成一个单独的可执行文件.     FreeWrap的原理是把脚本和tcl/tk解释器和库文件都打包 ...

  2. 学点css之经验总结篇章

    学css说起来应该有三天左右的时间的,加上之前了解的基础,对css有一点的感性认识了,相应代码有有比较好的把握,现在就通过分享几张照片的形式分享一下我的收获 备注:在Border的外边的部门被称作:o ...

  3. 一个用C#实现的虚拟WiFi设置程序

    前言:         本人常年使用Windows 7(虽然在努力学习Ubuntu,但是必须承认Windows 7上拥有大量的优秀软件,比如Evernote.Microsoft Office等).但是 ...

  4. SEVERE: Class [ com/mysema/query/dml/DeleteClause ] not found

    SEVERE:   Class [ com/mysema/query/dml/DeleteClause ] not found. Error while loading [ class org.spr ...

  5. weblogic9.2重置密码

    1.删除DefaultAuthenticatorInit.ldift 2.执行命令:java -cp /home/weblogic/bea/weblogic92/server/lib/weblogic ...

  6. OC - 7.Foundation框架的简单介绍

    OC语言-07-OC语言-Foundation框架   结构体 NSRange/CGRange 用来表示一个元素在另一个元素中的范围,NSRange等价于CGRange 包含两个属性: NSUInte ...

  7. weewwe

    http://blog.csdn.net/u013073524/article/details/25912891

  8. 09.13随笔2014年9月13日22:32:38,奶爸的英语教室,groovy

    我们这里只推荐一本语法书:台湾的旋元佑老师写的<文法俱乐部>(简体版名为<语法俱乐部>).这本书因为出版社倒闭而绝版,淘宝可以买到影印的版本. (1)学英语到 奶爸的英语教室  ...

  9. 360极速浏览器在XP系统下的一个bug

    今天在做页面开发的时候,发现360浏览器在XP系统下不支持focus事件,而主流的IE(包括IE6),firefox,chrome都没有这个问题.前段开发的悲剧啊,各种浏览器兼容性的问题.

  10. centOS 多网卡 启动网络 eth0 does not to be present

    centOS 6.4 中 em1 就是eth0... ---------------------------------------- http://www.php-oa.com/2012/03/07 ...