求数列的和

时间:2014-10-27 17:17:20   收藏:0   阅读:118

Problem Description

数列的定义如下:

数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。

 

Input

输入数据有多组,每组占一行,由两个整数n(n<10000)和m(m<1000)组成,n和m的含义如前所述。

 

Output

对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。

 

Sample Input

81 4

2 2

 

Sample Output

94.73

3.41

 

 1 #include <stdio.h>
 2 #include <math.h>
 3  
 4 int main(){
 5     double a;
 6     int b;
 7     int i;
 8     double result;
 9      
10      
11     while((scanf("%lf%d",&a,&b))!=EOF){
12         result=0;
13          
14         for(i=0;i<b;i++){
15             result+=a;
16             a=sqrt(a);
17         }
18          
19         printf("%.2lf\n",result);
20     }
21      
22     return 0;
23 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!