幸运数字的定义是这样:仅含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. 利用php给图片添加文字水印--面向对象与面向过程俩种方法的实现

    1: 面向过程的编写方法 //指定图片路径 $src = '001.png'; //获取图片信息 $info = getimagesize($src); //获取图片扩展名 $type = image ...

  2. jQuery滑过头像图片展示个人信息效果

    这是一款经典的jQuery图片插件,同时,也可以是一款jQuery提示框插件.这款jQuery插件的功能是当你把鼠标滑过头像图片缩略图时,即可弹出头像对应用户的详细个人信息,弹出的标签虽然不大,但是还 ...

  3. 20160409 javaweb 数据库连接池

    1.自己编写数据库连接池: package com.dzq.pool; import java.io.PrintWriter; import java.lang.reflect.InvocationH ...

  4. MVC小系列(十九)【mvc与站点地图】

    我的MvcSiteMap地图主要由实体文件,XML配置文件,C#调用文件组成,当然为了前台调用方法,可以为HtmlHelper添加一个扩展方法 第一步 定义站点地图实体 public class Mv ...

  5. PHP mysql_real_escape_string() 函数防SQL注入

    PHP MySQL 函数 定义和用法 mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符. 下列字符受影响: \x00 \n \r \ ' &quo ...

  6. PHP简单MVC架构

    http://blog.csdn.net/haiqiao_2010/article/details/12166283 由于需要搭建一个简单的框架来进行API接口开发,所以简单的mvc框架当然是首选.最 ...

  7. linux修改主机名(hostname)转载

    Linux修改主机名的方法 用hostname命令可以临时修改机器名,但机器重新启动之后就会恢复原来的值. #hostname   //查看机器名#hostname -i  //查看本机器名对应的ip ...

  8. cocoaPods的安装和使用之详细介绍

    一,在Mac OS X上安装Ruby运行环境 步骤1------安装RVM $ curl -L https://get.rvm.io | bash -s stable 然后载入RVM环境 $ sour ...

  9. iOS9的那些坑 — — WeiboSDK registerApp启动就崩溃

    在升级Xcode7.2.1后,在App加载时直接崩掉,仔细看了,发现是在在注册微博SDK的时候报错: [WeiboSDK registerApp:WBAPPKey]; 查了很多资料,最后在github ...

  10. OC - 8.Quartz2D核心要点

    简介 作用 绘制 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成PDF 截图\裁剪图片 自定义UI控件(通常为内部结构较复杂的控件) UIKit中的绝大部分控 ...