求T(m)的值

1.8k 词

题目描述

给定m根据以下公式计算T(m): T(m)=1-(1/(2*2))-….-(1/(m*m))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<h2 class="page-header text-muted">
输入
</h2>

<div class="content">
<p>
整型变量m范围[2,1000]
</p>
</div>

<h2 class="page-header text-muted">
输出
</h2>

<div class="content">
<p>
计算<span id="MathJax-Element-11-Frame" class="MathJax" style="box-sizing: border-box; font-size: 15px; display: inline; font-style: normal; font-weight: normal; line-height: normal; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;" tabindex="0" role="presentation" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>T</mi><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo stretchy=&quot;false&quot;>)</mo></math>"><span id="MathJax-Span-89" class="math"><span id="MathJax-Span-90" class="mrow"><span id="MathJax-Span-91" class="mi">T</span><span id="MathJax-Span-92" class="mo">(</span><span id="MathJax-Span-93" class="mi">m</span><span id="MathJax-Span-94" class="mo">)</span></span></span></span>(保留六位小数)
</p>
</div>

#include<bits/stdc++.h>
using namespace std;
int main(){
int m,i=1;
long double t,x,y;
t=1;
cin>>m;
while(i<m){
i=i+1;
x=i*i;
y=1/x;
t=t-y;
}
printf(“%.6Lf”,t);
return 0;
}