UVA10994 Simple Addition前缀和
Posted tigerisland45
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10994 Simple Addition前缀和相关的知识,希望对你有一定的参考价值。
Lets define a simple recursive function F(n), where
????Lets 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.
Output
For each set of input print a single line of the value of S(p, q).
Sample Input
1 10
10 20
30 40
-1 -1
Sample Output
46
48
52
问题链接:UVA10994 Simple Addition
问题简述:(略)
问题分析:
????数学计算问题,构造一个计算前缀和的函数实现。需要根据组合数学知识来推导公式。函数F(n)计算n的最右边非0数字。S(0,9)=45。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++程序如下:
/* UVA10994 Simple Addition */
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL sum(LL n)
{
LL ans = 0, x;
while(n) {
x = n % 10;
n /= 10;
ans += ((1 + x) * x) / 2 + n * 45;
}
return ans;
}
int main()
{
LL a, b;
while(~scanf("%lld%lld", &a, &b) && a >= 0)
printf("%lld
", sum(b) - sum(a - 1));
return 0;
}
以上是关于UVA10994 Simple Addition前缀和的主要内容,如果未能解决你的问题,请参考以下文章
HDU2451 Simple Addition expression(数位dp/找规律)
UVA10912 Simple Minded HashingDP