HDUOJ - Problem - 2009 求数列的和

HDUOJ - Problem - 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 <stdio.h>
#include <stdlib.h>
#include <math.h>

int m;
double n,sum,temp;

int main(int argc, char const *argv[])
{
	while(scanf("%Lf %d",&n,&m) == 2)
	{
		temp = n * n;
		sum = 0;
		for (int i = 1; i <= m; ++i)
		{
			temp = sqrt(temp);
			sum += temp;
		}
		printf("%.2Lf\n",sum);
	}
	system("pause");
	return 0;
}
发布了19 篇原创文章 · 获赞 23 · 访问量 3910

猜你喜欢

转载自blog.csdn.net/weixin_43737206/article/details/88724914