数学推导——特殊数列

问题:

特殊数列:后一项是前一项的平方根,先有第n的值,求n项到某项的和

分析:根据数列规则求解

code:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         Scanner s = new Scanner(System.in);
 7         double n;
 8         int m;
 9         
10         while(s.hasNext()) {
11             n = s.nextDouble();
12             m = s.nextInt();
13             double temp = n;
14             
15             //迭代求和
16             for(int i=1;i<m;i++) {
17                 temp = Math.sqrt(temp);
18                 n+=temp;
19             }
20             System.out.printf("%.2f\n",n);
21             
22         }
23         s.close();
24     }
25     
26 }

猜你喜欢

转载自www.cnblogs.com/dream-flying/p/12794799.html