题解 | #数列的和#
数列的和
http://www.nowcoder.com/practice/fe19f8a78a5148018f4be53ae9b5e11e
import java.util.Scanner;
public class Main {
/**
* 数列 n .. 的前 m 项和
* 输入:81 4 2 2
* 输出: 94.73 3.41
*/
public static void main(String[] args) {
run();
}
private static void nSum(int n, int m) {
double res = n;
double sum = 0;
for (int i = 0; i < m; i++) {
sum += res;
res = Math.sqrt(res);
}
System.out.println(String.format("%.2f", sum));
}
private static void run() {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String[] inputs = sc.nextLine().split(" ");
int n = Integer.parseInt(inputs[0]);
int m = Integer.parseInt(inputs[1]);
nSum(n, m);
}
}
}