Java Primality Test

  • + 0 comments
    public class Solution {
        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    
            String n = bufferedReader.readLine();
            BigInteger a = new BigInteger(n);
            boolean res = a.isProbablePrime(10);
            System.out.println((res) ? "prime" : "not prime");
            bufferedReader.close();
        }
    }