-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTprimeNumber.java
More file actions
56 lines (51 loc) · 1.34 KB
/
TprimeNumber.java
File metadata and controls
56 lines (51 loc) · 1.34 KB
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
54
55
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public final class TprimeNumber
{
static boolean isPrime(int n){
if(n==2||n==3||n==5 || n==7||n==11){
return true;
}
if(n%2==0||n%3==0||n%5==0||n%7==0)
return false;
for(int i=11;i*i<=n;i++){
if(n%i==0)
return false;
}
return true;
}
static boolean isTrimPrime(long n,boolean[] primes,int count){
int sqrt=(int)Math.sqrt(n);
if(primes[sqrt]==true && n==(long)sqrt*sqrt)
return true;
return false;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
boolean[] primes=new boolean[1000001];
int count=1;
primes[2]=true;
for(int i=3;i<=1000000;i+=2){
if(isPrime(i))
primes[i]=true;
}
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
String[] s=br.readLine().split(" ");
int i=0;
while(t>i){
if(isTrimPrime(Long.parseLong(s[i]),primes,count)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
i++;
}
br.close();
}
}