题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2009
题目大意:数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和
解题思路:
用好sqrt() 函数
1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 using namespace std; 5 int main() 6 { 7 double m; 8 int n; 9 while(cin >> m >> n) 10 { 11 double sum = 0; 12 for(int i = 0; i < n; i ++) 13 { 14 sum += m; 15 m = sqrt(m); 16 } 17 cout << fixed << setprecision(2) << sum << endl; 18 } 19 }
原文地址:https://www.cnblogs.com/mimangdewo-a1/p/9368402.html
时间: 2024-11-07 18:59:44