CF_Lucky Sum
幸运数字的定义是这样:仅含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的更多相关文章
- LeetCode - Two Sum
		
Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summa ...
 - 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 ...
 - Leetcode 笔记 112 - Path Sum
		
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
 - POJ 2739. Sum of Consecutive Prime Numbers
		
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
 - BZOJ 3944 Sum
		
题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不 ...
 - [LeetCode] Path Sum III 二叉树的路径和之三
		
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
 - [LeetCode] Partition Equal Subset Sum 相同子集和分割
		
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
 - [LeetCode] Split Array Largest Sum 分割数组的最大值
		
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
 - [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 ...
 
随机推荐
- A swift Tour(2) Control Flow
			
Control Flow 用 if 和 switch 来做条件语句,并且用for-in,for,while,和do-while做循环,条件和循环的括号是可以不写的,但是body外面的括号是必须写的 l ...
 - Repeater事件OnItemCommand取得行内控件
			
记录一下,主要是这句:TextBox txtNum = e.Item.FindControl("txtNum") as TextBox; Repeater真是太强了,太灵活.除了R ...
 - swift入门-day01
			
Swift 简介 简介 Swift 语言由苹果公司在 2014 年推出,用来撰写 OS X 和 iOS 应用程序 2014 年,在 Apple WWDC 发布 历史 2010 年 7 月,苹果开发者工 ...
 - swift-01-利用元组判断字符串出现次数
			
//问题的提出:有一个字符串 array = ["1","2","4","4","2"," ...
 - 小改动,大作为——C# 4.0中的微小改动
			
1.可选参数和命名实参 可选参数和命名实参就如同一对好基友,因为它们经常一起使用. 1.1 可选参数 可选参数重在“可选”,即在调用方法时,该参数可以明确指定实参,也可以不指定.如下代码所示,下面代码 ...
 - webapi之jsonp调用
			
定义跨域handle public class CorsHandler : DelegatingHandler { const string Origin = "Origin"; ...
 - 桶排序之python实现源码
			
tmp = [] def bucket_sort(old): for i in range(len(old)): tmp.append([]) for i in old: tmp[int( i * l ...
 - ASP.NET中的验证控件
			
ASP.NET提供了如下的控件: RequiredFieldValidator: 字段必填 (ControlTovalidate设定要验证的控件) RangeValidator: 值在给定的最大值,最 ...
 - ASP.Net大文件上传组件详解
			
首先右键单击网站根目录,在弹出的快捷菜单中,选择"添加引用"菜单项,弹出"添加引用",切换到"浏览"找到组件的Dll文件"Best ...
 - Google Web Designer 测试
			
这东东完全就是一个flash啊,简单测试,感觉就是个做HTML5动画的..不过暂时是beta版的, 官方安装版的半天打不开,这边有个绿色版的,需要的童鞋可以这里下载:百度网盘