题解:T594525 T1 青团
Taikoier_Ura · · 题解
思路
先筛出
好吧如果你过不了就只能是人傻常数大了。
Code:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100000 + 5;
int a[N], p[N];
bool vis[N];
int n, tot;
void get_prime() {
vis[1] = 1;
for (int i = 2; i <= 100000; i++) {
if (!vis[i]) {
p[++tot] = i;
}
for (int j = 1; j <= tot; j++) {
if (i * p[j] > 100000) {
break;
}
vis[i * p[j]] = true;
if (i % p[j] == 0) {
break;
}
}
}
}
bool is_prime(int x) {
if (x < 2) {
return false;
}
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
get_prime();
int ans = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int sum = 1;
for (int j = 1; j <= tot; j++) {
int cnt = 1;
while (a[i] % p[j] == 0) {
cnt++;
a[i] /= p[j];
}
sum *= cnt;
}
if (is_prime(sum)) {
ans++;
}
}
cout << ans;
return 0;
}