-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT_Primes.cpp
More file actions
156 lines (129 loc) · 2.98 KB
/
T_Primes.cpp
File metadata and controls
156 lines (129 loc) · 2.98 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long
#define f(n) for(int i=0;i<n;i++)
#define g(n) for(int j=0;j<n;j++)
#define int long long
#define endl '\n'
int i,j,k;
const int M = 1e9+7;
int arr[200010]={0};
vector<int> a,b,x;
vector<int> v={1,3,6,10,15};
int dx[4]={1,-1,1,-1}, dy[4]={-1,-1,1,1};
int N = 1e7;
vector<int> prime(N+1,1);
vector<int> store;
bool issquare(int n){
long long low=0,high=n;
long long mid;
while(low<=high){
mid=(low+high)/2;
if(mid*mid==n) return true;
else if(mid*mid<n){
low=mid+1;
}
else high=mid-1;
}
return false;
}
bool iscube(int n){
long long low=0, high=n;
long long mid;
while(low<=high){
mid=(low+high)/2;
if(mid*mid*mid==n) return true;
else if(mid*mid*mid<n){
low=mid+1;
}
else high=mid-1;
}
return false;
}
/*vector<int> bfsOfGraph(int V, vector<int> adj[]) {
int visit[V]={0};
visit[0]=1;
queue<int> q;
q.push(0);
vector<int> bfs;
while(!q.empty()){
int node = q.front();
q.pop();
bfs.push_back(node);
for(auto i:adj[node]){
if(!visit[i]){
q.push(i);
visit[i]=1;
}
}
}
return bfs;
}
void dfs(int node, vector<int> adj[], int vis[], vector<int> &ls){
vis[node]=1;
ls.push_back(node);
for(auto i:adj[node]){
if(!vis[i]) dfs(i,adj,vis,ls);
}
}
vector<int> dfsOfGraph(int V, vector<int> adj[]) {
int vis[V]={0};
int start=0;
vector<int> ls;
dfs(start,adj,vis,ls);
return ls;
}*/
/*bool dfs_cyclecheck(int node, int parent, vector<int> adj[], int vis[]){
vis[node]=1;
for(auto i:adj[node]){
if(!vis[node]){
if(dfs_cyclecheck(i,node,adj,vis)==true) return true;
}
else if(parent!=i){
return true;
}
}
return false;
}*/
void sieve(){
prime[0] = prime[1] = 0;
for (int i = 2; i <= sqrt(1e7); ++i) {
if (prime[i] == 1) {
for (int j = i * i; j <= 1e7; j += i) {
prime[j] = 0;
}
}
}
}
bool isprime(int n){
if(n==0 or n==1) return false;
for(int i=2;i*i<=n;i++){
if(n%i==0) return false;
}
return true;
}
void solve(){
int x;
cin>>x;
a.resize(x);
f(x) cin>>a[i];
f(x){
int n=sqrt(a[i]);
if(n*n==a[i]){
if(isprime(n)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else cout<<"NO"<<endl;
}
}
signed main(){
//ifstream in("input.txt");
//ofstream out("output.txt");
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int misery=1;
//cin>>misery;
while(misery--) solve();
}