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
*
*************************************************/
解题思路:
纯粹的数学题,没有输入,直接要求输出.直接给出的求和式子极限到无穷,无法直接计算.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
*
*************************************************/
相关文章推荐
- 1.m分解阶乘之和
- 2.几种递推数
- 3.欧拉函数
- 4.快速幂模m算法
- 5.扩展欧几里得&&中国剩余定理
- 6.数论_web
- Project Euler Problem 387 - Harshad Numbers - 深度优先
- 编程之美2015初赛A
- 数论题集
- 原根
- 阶与原根学习笔记
- HDU 1299 Diophantus of Alexandria
- Leftmost Digit(HDU 1060)
- Rightmost Digit(HDU 1061)
- ZOJ 2674 Strange Limit 欧拉定理
- LeetCode-Palindrome Number
- 组合数求模总结
- 【数论】组合数求模
- [BZOJ1041][HAOI2008][数学乱搞]圆上的整点
- HDU 5341 Gcd and Lcm