Java Primality Test

Sort by

recency

|

272 Discussions

|

  • + 0 comments

    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();
        BigInteger intger=new BigInteger(n);
        System.out.println(intger.isProbablePrime(10) ? "prime" : "not prime");
    
        bufferedReader.close();
    }
    

    }

  • + 0 comments
    import java.io.*;
    import java.math.*;
    class Solution{
        public static void main(String[]args) throws IOException{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String n=br.readLine();
            br.close();
            BigInteger bi=new BigInteger(n);
            if(bi.isProbablePrime(10)){
                System.out.println("prime");
            }else{
                    System.out.println("not prime");
                }
            }
        }
    
  • + 0 comments
    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();
            BigInteger bi = new BigInteger(n);
            System.out.println(bi.isProbablePrime(10) ? "prime" : "not prime");
            bufferedReader.close();
        }
    }
    
  • + 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();
        }
    }
    
  • + 0 comments

    System.out.println(new BigInteger(n).isProbablePrime(1)? "prime" : "not prime");