UVA10302 Summation of Polynomials【数学】

The following text was taken from a book of mathematics:
“The antidifference of a function f(x) is the function g(x) such that f(x) = g(x + 1) − g(x). So, if we have a summation of f(x), it can be simplified by the use of its antidifference in the following way:
f(k) + f(k + 1) + f(k + 2) + . . . + f(k + n) =
= g(k + 1) − g(k) + g(k + 2) − g(k + 1) + g(k + 3) − g(k + 2)+ . . . +g(k + n + 1) − g(k + n) =
= g(k + n + 1) − g(k)
    A factorial polynomial is expressed as k{n} meaning the following expression:
k ∗ (k − 1) ∗ (k − 2) ∗ . . . ∗ (k − (n − 1))
    The antidifference of a factorial polynomial k{n}is k{n+1}/(n + 1).”
    So, if you want to calculate Sn = p(1) +p(2) +p(3) +. . .+p(n), where p(i) is a polynomial of degree k, we can express p(i) as a sum of various factorial polynomials and then, find out the antidifference P(i). So, we have Sn = P(n + 1) − P(1).
Example:
S = 2∗3+ 3∗5+ 4∗7+ 5∗9+ 6∗11+. . .+ (n+ 1)∗(2n+ 1) = p(1)+p(2)+p(3)+p(4)+p(5)+…+p(n), where p(i) = (i + 1)(2i + 1).
    Expressing p(i) as a factorial polynomial, we have:
p(i) = 2i{2} + 5i + 1.
and then
P(i) = (2/3)i{3} + (5/2)i{2} + i.
    Calculating P(n + 1) − P(1) we have
S = (n/6) ∗ (4n2 + 15n + 17)
    Given a number 1 ≤ x ≤ 50, 000, one per line of input, calculate the following summation:
1 + 8 + 27 + … + x3
Input
Input file contains several lines of input. Each line contain a single number which denotes the value of x. Input is terminated by end of file.
Output
For each line of input produce one line of output which is the desired summation value.
Sample Input
1
2
3
Sample Output
1
9
36

问题链接UVA10302 Summation of Polynomials
问题简述:(略)
问题分析
    题目很长,读懂太难。实际上就是按公式公式:1^3 + 2^3 + 3^3 + … + n^3 = (1+2+3+…+n)^2. 来计算。可以通过归纳法证明该公式是成立的。由于对于给定的n,求和后再做乘法计算结果不会超过二进制64位,所以程序就简单了。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10302 Summation of Polynomials  */

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ULL;

int main()
{
    ULL n, sum;
    while(scanf("%llu", &n) == 1) {
        sum = n * (n + 1) / 2;
        printf("%llu\n", sum * sum);
    }

    return 0;
}
发布了2128 篇原创文章 · 获赞 2306 · 访问量 254万+

猜你喜欢

转载自blog.csdn.net/tigerisland45/article/details/104592770