forked from ashoklathwal/Code-for-Interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primality.java
53 lines (49 loc) · 1.25 KB
/
Primality.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
/*
generate all prime numbers or within range
static int[] primeGen(int q)
{
int[] arr = new int[q];
BigInteger bi = BigInteger.valueOf(1);
for(int i=0; i<q; i++)
{
bi = bi.nextProbablePrime();
arr[i] = bi.intValue();
}
// System.out.println(Arrays.toString(arr));
return arr;
}
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int p = in.nextInt();
for(int a0 = 0; a0 < p; a0++)
{
int n = in.nextInt();
boolean flag=true;
if(n==1)
{
flag=false;
}
for(int i=2;i<=Math.sqrt(n);i++)
{
if(n%i==0)
{
flag=false;
break;
}
}
if(flag)
System.out.println("Prime");
else
System.out.println("Not prime");
}
}
}