标签:mes c++ scanf space its namespace ace div using
选自一道初中奥数题:
1/(2*sqrt(1)+sqrt(2))+1/(3*sqrt(2)+2*sqrt(3))+1/(4*sqrt(3)+3*sqrt(4))+…+1/((n+1)*sqrt(n)+n*sqrt(n+1)) = ?
我们先研究一下通项:
可以发现:
1/((n+1)*sqrt(n)+n*sqrt(n+1)) = 1/(sqrt(n)*sqrt(n+1)*(sqrt(n)+sqrt(n+1)) = (分子分母同时乘上sqrt(n)+sqrt(n+1) 的 有理化因式)1/(sqrt(n)*sqrt(n+1)) = (注意到:形如 1/(ab) = 1/a - 1/b (a>b) , 所以)
1/sqrt(n) - 1/sqrt(n+1)
所以:原式 = 1/sqrt(1) - 1/sqrt(2) + 1/sqrt(2) - 1/sqrt(3) +...+1/sqrt(n) - 1/sqrt(n+1) = (中间列项相消) = 1 - sqrt(n+1)
标程如下:
#include<bits/stdc++.h> using namespace std; long long n; int main() { scanf("%lld",&n); cout<<fixed << setprecision(10) << 1 - 1/sqrt(n+1)<<endl; return 0; }
标签:mes c++ scanf space its namespace ace div using
原文地址:http://www.cnblogs.com/YMY666/p/7954587.html