uva 10302 summation of polynomials
来源:互联网 发布:pymongo 连接数据库 编辑:程序博客网 时间:2024/05/24 01:50
Problem C
Summation of Polynomials
Input: standard input
Output: standard output
Time Limit: 1 second
Memory Limit: 32 MB
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 S_n = 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 S_n = 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) = 2(i)^{2} + 5i + 1.
P(i) = (2/3) (i)^{3} + (5/2) (i)^{2} + i. Calculating P(n+1) - P(1) we have
S = (n/6) * (4n^2 + 15n + 17)
Given a number 1 <= x <= 50,000, one per line of input, calculate the following summation:
1 + 8 + 27 + ... + x^3
Input and Output
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.
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
(The Joint Effort Contest, Problem setter: Rodrigo Malta Schmidt)
虽然没有推导出公式还是能AC,还是按照提示推出了公式。
#include <cstdio>int main () { long long a; while (scanf ("%lld", &a) == 1) { printf ("%lld\n", (a*a*a*a + 2*a*a*a + a*a) / 4); } return 0;}
#include <cstdio>int main () { int x; while (scanf ("%d", &x) == 1) { long long s = 0; for (long long i=1; i<=x; ++i) { s += i * i * i; } printf ("%lld\n", s); } return 0;}
- uva 10302 summation of polynomials
- UVA-10302-Summation of Polynomials
- UVa 10302 - Summation of Polynomials
- UVa OJ 10302-Summation of Polynomials
- uva 10168 summation of four primes
- Uva 10168 Summation of Four Primes 素数
- UVA-10168 Summation of Four Primes
- UVa 10168 - Summation of Four Primes
- Uva 10168 - Summation of Four Primes
- UVa 10168 Summation of Four Primes
- UVa Problem Solution: 10168 - Summation of Four Primes
- PC/UVa 110705/10168 Summation of Four Primes
- (数论2.1.2)UVA 10168Summation of Four Primes(欧拉筛法)
- UVA 10168 Summation of Four Primes(数论)
- uva 10168 Summation of Four Primes(数论-哥德巴赫猜想)
- UVa 10168 Summation of Four Primes(数论-哥德巴赫猜想)
- 数论刷题-uva【10168】- Summation of Four Primes
- summation of four primes
- 一些数据的转化
- Class文件内容及常量池
- 关于mentohust认证中出现“不允许使用的客户端类型”问题方案
- sybase 错误码
- 炖肉又熟又烂的小窍门
- uva 10302 summation of polynomials
- net中C#自动化调用Word的实例总结
- C#学习日志(12)
- 山西煤老板用20万1元钱付饭钱
- while(!feof(...)) 中加if(!feof(...)) 问题
- C# 反射技术测试笔记
- 性能监控与性能问题定位之:Java篇
- xml文件操作方式之一
- 当,习惯一个人