10994 - Simple Addition(规律)
Problem E
Simple Addition
Input: Standard Input
Output: Standard Output
Let’s define a simple recursive function F (n), where

Let’s define another function S (p, q),

In this problem you have to Calculate S (p, q) on given value of p and q.
Input
The input file contains several lines of inputs. Each line contains two non negative integers p and q (p <= q) separated by a single space. p and q will fit in 32 bit signed integer. In put is terminated by a line which contains two negative integers. This line should not be processed.
For each set of input print a single line of the value of S(p, q).
Sample Input Output for Sample Input
|
1 10 10 20 30 40 -1 -1 |
46 48 52 |
题意:求题目中那个公式从p到q F【i] 的和
思路:每个数肯定是1-9.这样的规律,个位1-9,十位1-9,百位1-9.如此一来,只要把各位加完,加十位,加百位,一个个加完,最后就是答案了。加的时候可以直接用等差数列和公式
代码:
#include <stdio.h>
int p, q;
long long Sum(long long s, long long e) {
if (s > e)
return 0;
return (s + e) * (e - s + 1) / 2;
}
long long cal(long long n) {
if (n <= 0) return 0;
long long ans = 0;
while (n) {
ans += n / 10 * 45;
ans += Sum(1, n % 10);
n /= 10;
}
return ans;
}
int main() {
while (~scanf("%d%d", &p, &q) && p != -1 && q != -1) {
printf("%lld\n", cal(q) - cal(p - 1));
}
return 0;
}
10994 - Simple Addition(规律)的更多相关文章
- uva 10994 - Simple Addition(规律)
题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...
- uva 10994 - Simple Addition
//组合数学 //计算sum{i从右往左数的第一个非0数字,p<=i<=q}. #include <cstdio> typedef long long ll; ll sum(l ...
- 组合数学第一发 hdu 2451 Simple Addition Expression
hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...
- HDU 2451 Simple Addition Expression(组合数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...
- HDU2451:Simple Addition Expression
Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...
- 【计数】Simple Addition Expression
[来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...
- HDU 2451 Simple Addition Expression(找规律,考验智商)
题目 最近比赛的题目好多签到题都是找规律的考验智商的题目啊,,,我怎么越来越笨了,,,, 通过列举,可以发现规律: 从左往右按位扫这个数: 当数的长度大于1时: 当首位大于3时,答案就是4*4*4*… ...
- 【HDOJ】2451 Simple Addition Expression
递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...
- HDU 2451 Simple Addition Expression
题目大意:有一个关于 简单加法表达式 的定义告诉你,就是 选一个数字i 如果 i+(i+1)+(i+2) 它的和,没有任何一位进位的话,那就是 一个i的简单加法表达式,求小于n的表达式数目. 题 ...
随机推荐
- C++ 面向对象学习2 构造方法
Date.h #ifndef DATE_H #define DATE_H class Date{ public: Date(,,);//自定义了构造方法 会覆盖掉默认的无参构造方法 void setD ...
- Maven本地
<localRepository></localRepository>
- [cocos2dx笔记011]使用Cocostudio UI编辑器
本文地址:http://www.cppblog.com/zdhsoft/archive/2014/07/19/207715.html 笔记汇总:http://www.cppblog.com/zdhso ...
- 【Android病毒分析报告】 - ZxtdPay 吸费恶魔
本文章由Jack_Jia编写,转载请注明出处. 文章链接:http://blog.csdn.net/jiazhijun/article/details/11581543 作者:Jack_Jia ...
- 玩转Bootstarp(连载)
一.Bootstarp是什么? 简单.灵活的用于搭建WEB页面的HTML.CSS.JS的工具集 (基于HTML5和CSS3) 总结:简洁强大的前端开发框架,可以让WEB开发更迅速.更简单 二.如何使用 ...
- Android Studio导出Jar包
这篇博客将介绍一下如何用Android Studio导出jar包,希望能给大家带来帮助. 首先需要修改build.gradle文件,在Android Studio中会显示多个build.gradle文 ...
- iOS 项目中的NSNotification简单使用
iOS中NSNotification的简单使用 好久没有写过博客了,总是遇到问题查一下,今天查的又是一个老问题,想了想,还是记录一下!今天在项目开发中遇到一个配置及时性处理的问题,想了想之后决定用通知 ...
- HDU 4548(美素数)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 小明对数的 ...
- ansible笔记
ansible 资料 ansible 配置 ansible inventory配置文件 ansible模块 http://www.cnblogs.com/iois/p/6216936.html ans ...
- c语言: 文件io, 拷贝文件(二进制)
#include <stdio.h> #include <stdlib.h> #define TRAN_SZIE 1024 int copy_bin(char* from, c ...