Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 14 years ago.
function do(int n) { if(n==1) return n; return 1/n + do(--n); }
这是一种查看方法:
http://www.wolframalpha.com/input/?i=sum+1/j,+j%3D1+to+n
Here's one way to look at it:
如果我正确理解你的问题,阅读本文应该对你有帮助: http://en.wikipedia.org/wiki /Harmonic_number
If I understood you question correctly, reading this should help you: http://en.wikipedia.org/wiki/Harmonic_number
由于它是调和级数,总和为n,您正在寻找第 n 个谐波数,大约由下式给出γ + ln[n],其中 γ 是 欧拉-马斯切罗尼常数。
n
γ + ln[n]
γ
对于较小的n,直接计算总和即可:
double H = 0; for(double i = 1; i < (n+1); i++) H += 1/i;
As it is the harmonic series summed up to n, you're looking for the nth harmonic number, approximately given by γ + ln[n], where γ is the Euler-Mascheroni constant.
For small n, just calculate the sum directly:
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(4)
这是一种查看方法:
http://www.wolframalpha.com/input/?i=sum+1/j,+j%3D1+to+n
Here's one way to look at it:
http://www.wolframalpha.com/input/?i=sum+1/j,+j%3D1+to+n
如果我正确理解你的问题,阅读本文应该对你有帮助: http://en.wikipedia.org/wiki /Harmonic_number
If I understood you question correctly, reading this should help you: http://en.wikipedia.org/wiki/Harmonic_number
由于它是调和级数,总和为
n
,您正在寻找第 n 个谐波数,大约由下式给出γ + ln[n]
,其中γ
是 欧拉-马斯切罗尼常数。对于较小的
n
,直接计算总和即可:As it is the harmonic series summed up to
n
, you're looking for then
th harmonic number, approximately given byγ + ln[n]
, whereγ
is the Euler-Mascheroni constant.For small
n
, just calculate the sum directly: