Square root of the sequence and Java

Source: Internet
Author: User

Title Description:

The sequence is defined as follows:
The first item of the sequence is n, and the sum of the first m of the sequence is calculated after the square root of the previous item.

Input

There are several groups of input data, one row for each group, consisting of two integers n (n<10000) and M (m<1000), and the meanings of N and M as described earlier.

Output

For each set of input data, output the summation of the series, each test instance occupies one row, requiring precision to retain 2 decimal places.

Sample input

81 4
2 2

Sample output

94.73
3.41

The implementation is as follows:

Import java.util.*;

public class Main {
public static void Main (string[] args) {
Scanner sc=new Scanner (system.in);
while (Sc.hasnext ()) {
Double N=sc.nextint ();
Double M=sc.nextint ();
Double sum=0;
for (int i=0;i<m;i++)
{
Sum+=n;
N=MATH.SQRT (n);
}
System.out.printf ("%.2f\n", sum);
}
}
}

Square root of the sequence and Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.