forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path113.cpp
More file actions
61 lines (53 loc) · 1013 Bytes
/
113.cpp
File metadata and controls
61 lines (53 loc) · 1013 Bytes
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
//ac
#include <iostream>
using namespace std;
long long plist[10000],pcount=0;
int prime(int n){
int i;
if ((n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!=7&&!(n%7)))
return 0;
for (i=0;plist[i]*plist[i]<=n;i++)
if (!(n%plist[i]))
return 0;
return n>1;
}
void initprime(){
int i;
for (plist[pcount++]=2,i=3;i<50000;i++)
if (prime(i))
plist[pcount++]=i;
}
bool f(long long n) {
if (n == 1) return false;
if (n == 2 || n == 3) return true;
long long num = 3;
long long n2 = (long long)sqrt((double) n) + 1;
for (long long i = 2; i <= n2; ++i) {
if (n % i == 0) return false;
}
return true;
}
void run() {
long long n;
cin >> n;
long long n2 = (long long)sqrt((double) n) + 1;
for (int i = 0; i < pcount; ++i) {
if (plist[i] > n2) break;
if (n % plist[i] == 0) {
if (f(n / plist[i])) {
printf("Yes\n");
} else {
printf("No\n");
}
return;
}
}
printf("No\n");
}
int main() {
initprime();
int n;
for (scanf("%lld", &n); n; --n) {
run();
}
}