HDOJ 2009 求数列的和

来源:互联网 发布:linux重启apache 编辑:程序博客网 时间:2024/06/05 07:54

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2009

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

题解

#include <math.h>#include <stdio.h>int main(void){    int n;    double x, s;    while (scanf("%lf%d", &x, &n) != EOF)    {        for(s = 0.0; n--; x = sqrt(x)){s += x;}        printf("%.2lf\n", s);    }    return 0;}

0 0
原创粉丝点击