find the sum of the sequence

Topic description

The first item of the sequence is n, and the following items are the square root of the previous item. Find the sum of the first m items of the sequence.

Enter description:

There are multiple groups of input data, each group occupies a row, and consists of two integers n (n < 10000) and m (m < 1000). The meanings of n and m are as described above.

Output description:

For each set of input data, output the sum of the sequence, each test instance occupies a row, and the precision is required to retain 2 decimal places.
Example 1

enter

81 4
2 2

output

94.73
3.41
1  import java.text.DecimalFormat;
 2  import java.util.Scanner;
 3  /** 
4  * 
 5  * find the sum of the number column
 6          pay attention to the carry
 7          pay attention to the format
 8  * @author Dell
 9  *
 10   */ 
11  public  class Main {
 12  public  static  void main(String[] args) {
 13      Scanner sc = new Scanner(System.in);
 14      double n = sc.nextFloat();
 15      double m = sc.nextFloat();
16     double sum = 0;
17     for (int i = 0; i < m; i++) {
18         sum+=n;
19         n=Math.sqrt(n);
20     }
21     DecimalFormat df = new DecimalFormat("#.00");
22     String res = df.format(sum);
23     System.out.println(res);
24 }
25 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325165619&siteId=291194637