You are viewing a single comment's thread. Return to all comments →
I try this
public static void main(String[] args) throws IOException { BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(System.in)); String n= bufferedReader.readLine(); bufferedReader.close(); BigInteger p= new BigInteger(n); String result=prime(p); System.out.println(result); } public static String prime(BigInteger a){ for (int i = 2; a.compareTo(BigInteger.valueOf(i))>0 ; i++) { if(a.remainder(BigInteger.valueOf(i)).equals(BigInteger.ZERO)){ return "not prime"; } } return "prime"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Primality Test
You are viewing a single comment's thread. Return to all comments →
I try this