解析:对每个数分解质因数,并统计质因数个数,详见代码:
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
int cnt = 0;//质因数个数
for(int j = 2; j * j <= x; j++) {
if (x % j == 0){
cnt++;
}
while(x % j == 0) {
x /= j;
}
}
if (x > 1) {
cnt++;
}
if (cnt == 2) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
return 0;
}
标签:cnt,CCF,int,个数,T2,C++,2024,质因数,namespace From: https://blog.csdn.net/qq_36230375/article/details/140264081