开方数列和

数列的和

http://www.nowcoder.com/questionTerminal/fe19f8a78a5148018f4be53ae9b5e11e

注意输出答案的时候换行:

import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt(), m = sc.nextInt();
            double a = n, r = 0;
            while(m-- > 0){
                r += a;
                a = Math.sqrt(a);
            }
            System.out.printf("%.2f\n", r);
        }
    }
}
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务