-
Notifications
You must be signed in to change notification settings - Fork 4
/
113.cpp
48 lines (46 loc) · 932 Bytes
/
113.cpp
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
/*
*NAME:Nearly prime numbers
*LANG:C++
*Source:sgu113
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int t,n,num,k;
int prime[7000];
bool check[33001];
bool checkIt(int x){
if (x==1) return false;
int y = sqrt(x);
for (int i=0;i<num;++i){
if (prime[i]>y) return true;
if (x%prime[i] == 0) return false;
}
return true;
}
int main(){
memset(check,true,sizeof(check));
for (int i=2;i<=33000;++i){
if (check[i]) prime[num++]=i;
for (int j=0;j<num;++j){
if (prime[j]*i>33000) break;
check[prime[j]*i]=false;
if (i%prime[j]==0) break;
}
}
scanf("%d",&t);
for (int i=1;i<=t;++i){
cin >> k;bool f=false;
for (int j=0;j<num;++j){
if (k % prime[j]==0 && checkIt(k/prime[j])){
printf("%s\n","Yes");f=true;
break;
}
if (prime[j]>sqrt(k)) break;
}
if (!f) printf("%s\n","No");
}
}