Hacker rank Java Big integer Java primality Test
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String n = bufferedReader.readLine();
// Long n1=Long.parseLong(n);
//System.out.println(n);
//int n1=Integer.valueOf(n);
/*int sum=0;
while (n1 != 0)
{
sum = sum + n1 % 10;
n1 = n1/10;
}
System.out.println(sum);*/
BigInteger b1;
//Random r1=new Random();
//int length=sum;
//b1=BigInteger.probablePrime(length,r1);
//System.out.println(b1);
//boolean a=b1.isProbablePrime(n1);
b1=new BigInteger(n);
boolean a=b1.isProbablePrime(100);
if(a==true){
System.out.println("prime");
}
else
System.out.println("not prime");
bufferedReader.close();
}
}
Comments
Post a Comment