-
Notifications
You must be signed in to change notification settings - Fork 0
/
Java Primality Test.java
53 lines (37 loc) · 1.23 KB
/
Java Primality Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
A prime number is a natural number greater than whose only positive divisors are and itself. For example, the first six prime numbers are , , , , , and .
Given a large integer, , use the Java BigInteger class' isProbablePrime method to determine and print whether it's prime or not prime.
Input Format
A single line containing an integer, (the number to be checked).
Constraints
contains at most digits.
Output Format
If is a prime number, print prime; otherwise, print not prime.
Sample Input
13
Sample Output
prime
Explanation
The only positive divisors of are and , so we print prime.
*/
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String n = bufferedReader.readLine();
bufferedReader.close();
BigInteger number = new BigInteger(n);
if(number.isProbablePrime(1)){
System.out.println("prime");
}
else{
System.out.println("not prime");
}
}
}