幸运数字的定义是这样:仅含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. c#的方法重写和的java方法重写有什么区别

    java code: package example; class m1 { public int getInt() { return 0; } } class m2 extends m1 { pub ...

  2. js_BOM_05

    1.下拉级联   |-select的API      |-如何获得选中的option?      |-如何创建option?      |-如何将option添加到select?      |-如何移 ...

  3. web开发学习之旅---html第二天

    一.转义符 一些字符在html中拥有特殊的含义,比如小于号(<)用于定义 HTML 标签的开始.如果我们希望浏览器正确地显示这些字符,我们必须在 HTML 源码中插入转义符. 分类 二.html ...

  4. hdoj1874 (优先队列+Dijkstra)

    hdoj1874 分析: 一看题目, 就是求最短路, 这道题用的是Dijkstra+优先队列.先说一下Dijkstra算法:每次扩展一个距离最短的节点, 更新与其相邻点的距离. 当所有边权都为正时, ...

  5. Javase中多态polymorphic的简单介绍

    -------------多态-----------------  (1)面向对象三大核心思想:    1.封装 2.继承 3.多态 (2)多态定义:父类的引用指向子类的对象.   (3)引用指的是父 ...

  6. 修改sqlplus提示符

    如图所示 : 修改 提示符为 username(sid_serial#)@instance_name ,这样其实很方便的 以下是步骤 在11g中glogin.sql 文件是不存在的,取而代之的是 lo ...

  7. ReactNative-----环境搭建二(android)

    一.初始化一个ReactNative项目 在指定目录运行命令:react-native init Vince(项目名称)  //其过程就是在使用CLI工具构建项目, 命令行代码 F:\React> ...

  8. jQuery 常用代码集锦

    1. 选择或者不选页面上全部复选框 var tog = false; // or true if they are checked on load $('a').click(function() { ...

  9. SpringMVC的文件上传

    首先导入jar包 在springMVC里面配置文件上传,以及限定上传文件的大小  <bean id="multipartResolver" class="org.s ...

  10. 九度OJ 1087 约数的个数

    题目地址:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...