根据数列的定义,求前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)); } } }