The number of prime numbers makes PI to represent the first primes. Current to two positive integers m <= N <= 10000, please output PM to PN for all primes.

Source: Internet
Author: User
Enter a description:
The input gives M and N in a row, separated by a space.


Output Description:
Outputs all prime numbers from PM to PN, 1 rows per 10 digits, separated by spaces, but no extra space at the end of the line.

Enter an example:
5 27

Output Example:
of

47 53 59 61 67 71 73 79 83 89

97 101 103

Import java.util.ArrayList;
Import java.util.List;

Import Java.util.Scanner;
	        public class Test {public static void main (string[] args) {Scanner in = new Scanner (system.in);
			while (In.hasnextint ()) {//Note while processing multiple case int N = In.nextint ();
			int M = In.nextint ();
			list<integer> list = Jisuan (N, M);
		Printnum (N, M, list); The calculated prime number private static list<integer> Jisuan (int N, int M) {list<integer> List = new Arraylist<in
		Teger> ();
			for (int a = 2; a < Integer.max_value a++) {int temp = (int) math.sqrt (a);
			if (a = = 2) {List.add (a);
					else {for (int i = 2; I <= temp. i++) {if (a% i = = 0) {break;
					} if (I >= temp) {list.add (a);
			}} if (List.size () = N + M) {break;
	} return list;
		}//format output static void Printnum (int N, int M, list<integer> List) {int line = 0; if (N-2 >=0) {for (int i = N-2; i < M-1; i++) {if (Line% 10 = 9 | |
				i = = = M-2) {System.out.print (List.get (i));
				else {System.out.print (List.get (i) + "");
				} line++;
				if (line% = = 0) {System.out.println (); }} else {for (int i = N-1 i < M i++) {if line% = 9 | | i = = M-1) {System.out.print (list
				. get (i));
				else {System.out.print (List.get (i) + "");
				} line++;
				if (line% = = 0) {System.out.println ();
 }
			}
		}
	}
}




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.