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 ();
}
}
}
}
}