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   and q.

 

Input

The input file contains several lines of inputs. Each line contains two non negative integers 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(规律)的更多相关文章

  1. uva 10994 - Simple Addition(规律)

    题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...

  2. uva 10994 - Simple Addition

    //组合数学 //计算sum{i从右往左数的第一个非0数字,p<=i<=q}. #include <cstdio> typedef long long ll; ll sum(l ...

  3. 组合数学第一发 hdu 2451 Simple Addition Expression

    hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...

  4. HDU 2451 Simple Addition Expression(组合数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...

  5. HDU2451:Simple Addition Expression

    Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...

  6. 【计数】Simple Addition Expression

    [来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...

  7. HDU 2451 Simple Addition Expression(找规律,考验智商)

    题目 最近比赛的题目好多签到题都是找规律的考验智商的题目啊,,,我怎么越来越笨了,,,, 通过列举,可以发现规律: 从左往右按位扫这个数: 当数的长度大于1时: 当首位大于3时,答案就是4*4*4*… ...

  8. 【HDOJ】2451 Simple Addition Expression

    递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...

  9. HDU 2451 Simple Addition Expression

    题目大意:有一个关于 简单加法表达式  的定义告诉你,就是  选一个数字i  如果 i+(i+1)+(i+2) 它的和,没有任何一位进位的话,那就是 一个i的简单加法表达式,求小于n的表达式数目. 题 ...

随机推荐

  1. java和.net 处理任意格式日期字符串转日期类型,

    1.SimpleDateFormat.parse 把指定格式字符串转日期类型 public static Calendar convToCalender(String str,String templ ...

  2. Python之路Day2

    -->the start 养成好习惯,每次上课的内容都要写好笔记. 第二天内容主要是熟悉int.long.float.str.list.dict.tuple这几个类的内建方法. 对于Python ...

  3. android——manifest.xml

  4. Maven本地

    <localRepository></localRepository>

  5. spring与redis集成之aop整合方案

    java使用redis缓存可以使用jedis框架,jedis操作简单,没有什么复杂的东西需要学习,网上资料很多,随便看看就会了. 将spring与redis缓存集成,其实也是使用jedis框架,只不过 ...

  6. 【Leetcode】Triangle

    给定一个由数字组成的三角形,从顶至底找出路径最小和. Given a triangle, find the minimum path sum from top to bottom. Each step ...

  7. 1043 - Triangle Partitioning(数学)

    1043 - Triangle Partitioning   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit ...

  8. C++ 经常使用类 string类

    ===6.3.2使用string对象=== string word="I love China" *链接字符串* string description=adjective  + & ...

  9. ServiceBase 类

    https://msdn.microsoft.com/zh-cn/library/System.ServiceProcess.ServiceBase%28v=vs.80%29.aspx 为将作为服务应 ...

  10. 创建BDC(Business Data Connectivity Service)

    创建Business Data Connectivity http://blog.csdn.net/spfarm/article/details/44015915 创建和使用Business Data ...