39 lines
702 B
C++
39 lines
702 B
C++
#include <bits/stdc++.h>
|
||
using namespace std;
|
||
|
||
bool isPrime(int x) {
|
||
for (int i = 2; i <= x / i; i++) {
|
||
if (x % i == 0)
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool isLucky(int x) {
|
||
// 将数字x分解质因数,并且记录质因数的个数,如果质因数个数为2,并且不能重复,则返回true,否则返回false
|
||
int cnt = 0;
|
||
for (int i = 2; i <= x; i++) {
|
||
if (x % i == 0 && isPrime(i))
|
||
cnt++;
|
||
}
|
||
return cnt == 2;
|
||
}
|
||
/*
|
||
3
|
||
7 12 30
|
||
|
||
参考答案:0 1 0
|
||
*/
|
||
int main() {
|
||
int n;
|
||
cin >> n;
|
||
while (n--) {
|
||
int x;
|
||
cin >> x;
|
||
if (isLucky(x))
|
||
cout << 1 << endl;
|
||
else
|
||
cout << 0 << endl;
|
||
}
|
||
return 0;
|
||
} |