Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, Pascal, Perl, PHP, Python, Ruby, Rust, Scratch, Swift
Cho số nguyên dương ~n~, tính:
$${S_n} = \mathop {\sqrt {1 + \sqrt {2 + \sqrt {3 + ... + \sqrt {n - 1 + \sqrt n } } } } }\limits_{(n\text{ dấu căn bậc hai})}$$
Input
- Dòng đầu ghi số nguyên dương ~T~ là số bộ test;
- ~T~ dòng tiếp theo, mỗi dòng chứa một số nguyên dương ~n~.
Giới hạn:
- ~1 ≤ T ≤ 10^2, 1 ≤ n ≤ 10^3~.
Output
- Với mỗi bộ test, ghi ra trên một dòng số ~S_n~ làm tròn đến ~5~ chữ số thập phân.
Sample
Input #1
2
1
3
Output #1
1.00000
1.71227
Problem source: Chuyên Sơn La Online Judge
Bình luận
https://luyencode.net/edit/profile/
include <bits/stdc++.h>
define int long long
using namespace std;
double s; int t, i, n;
signed main() { iosbase::syncwith_stdio(false); cin.tie(0); cout.tie(0); freopen("INPUT.txt","r",stdin); freopen("OUTPUT.txt","w",stdout); cin >> t; while(t--) { cin >> n; s = 0; for(int i = n; i >= 1; i--) { s = sqrt(s + i); } cout << fixed << setprecision(5) << s << endl; } return 0; }
#include <bits/stdc++.h>
using namespace std; double s,S; long long t,i,n; int main(){ cin>>t; while(t--) { cin>>n; s=0; for(i=n;i>=1;i--) s=sqrt(s+i); cout<< fixed << setprecision (5) << s << endl; } }