HDOJ 2009 求数列的和

来源:互联网 发布:vmware 端口转发 编辑:程序博客网 时间:2024/06/07 15:17

        根据数列的定义,求前m项的和,注意输出精度。

package introduction;import java.text.DecimalFormat;import java.util.Scanner;/** * Created by YangYuan on 2017/12/8. */public class Problem2009{    public static void main(String[] args)    {        DecimalFormat df = new DecimalFormat("0.00");        Scanner scanner = new Scanner(System.in);        while (scanner.hasNext())        {            double n = scanner.nextInt();            int m = scanner.nextInt();            double sum = n;            for (int i = 1; i < m; i++)            {                n = Math.sqrt(n);                sum += n;            }            System.out.println(df.format(sum));        }    }}

原创粉丝点击