zoukankan      html  css  js  c++  java
  • 杭电ACM2009求数列的和

    求数列的和

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 22564    Accepted Submission(s): 13827


    Problem Description
    数列的定义如下:
    数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。
     
    Input
    输入数据有多组,每组占一行,由两个整数n(n<10000)和m(m<1000)组成,n和m的含义如前所述。
     
    Output
    对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。
     
    Sample Input
    81 4
    2 2
     
    Sample Output
    94.73
    3.41
     1 import java.text.DecimalFormat;
    2 import java.util.Scanner;
    3 public class Main{
    4 public static double Sum(int n,int m){
    5 double sum = 0;
    6 double temp = n;
    7 for(int i=1;i<=m;i++){
    8 sum += temp;
    9 temp = Math.sqrt(temp);
    10 }
    11 return sum;
    12 }
    13 public static void main(String[] args) {
    14 Scanner scan = new Scanner(System.in);
    15 int m,n;
    16 while(scan.hasNextInt()){
    17 n = scan.nextInt();
    18 m = scan.nextInt();
    19 DecimalFormat mydf = new DecimalFormat("#####0.00");
    20 System.out.println(mydf.format(Sum(n,m)));
    21 }
    22 }
    23 }
  • 相关阅读:
    ShiroConfig V2.0
    MyRealm V2.0(注:加上了权限字符串)
    ShiroUtils通用工具包
    ResourcesConfig实现配置资源路径
    MyRealm V1.0
    ShiroConfig V1.0
    MySQL
    Git实战
    scala中函数简单使用记录
    scala中Trait简单使用
  • 原文地址:https://www.cnblogs.com/bchxsx322/p/2431996.html
Copyright © 2011-2022 走看看