您的位置:首页 > 其它

ZOJ1007(数论)

2015-10-23 22:14 218 查看
题目链接:点击打开链接

解题思路:

  纯粹的数学题,没有输入,直接要求输出.直接给出的求和式子极限到无穷,无法直接计算.Hint里给出了提示,大意就是说求g(x) - g(1)的求和极限,最后再加上g(1)就能求出g(x).

  由g(x)  - g(1) 能够得出 1 / k*(k+x) - 1 / k * (k + 1) = (1 - x) / k * ( k + 1) * (k + x) ,分母是3次方,题目精度要求达到-1e12,所以这里循环最大取到1e4即可.

  最后求余项,根据第三个不等式,可知 (1 - x) / k * ( k + 1) * (k + x) 的余项 为(1 - x) sum (1 / k ^3) = 积分函数 f (1 / (x ^ 3) , x) , 解得 (1 - x) / (2 * n * n),也可以理解为保留精度所以加上1e4之后的和,之后把g(1) = 1加上即可.

完整代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <time.h>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 100001;

int main()
{
double x = 0.000 , sum =0;
while(x <= 2.000)
{
sum = 0;
for(int i = 1 ; i < 1e4 ; i++)
sum += ((1.0 - x) / ( i * (i + 1.0) * (i + x)));
sum += (1.0 - x) / (2 * 1e4 * 1e4) + 1.0;
printf("%5.3f %16.12f\n" , x , sum);
x += 0.001;
}
return 0;
}

/*************************************************
*
* Copyright By DoubleQ
* Written in 2015
* Blog Address : zhanghe.ac.cn
* http://blog.csdn.net/u013447865 * Email Address: acmer_doubleq@qq.com
*
*************************************************/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数论