Files
python/GESP/Level5/GESP202406/20240602.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

39 lines
702 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}