CF1033D
题意
傻逼题
做法1
不能这样写
for (auto x: p) if(a % x == 0) p.push_back(a / x);
在 for(auto x: p) 中不能对 p 修改。
代码
#include <bits/stdc++.h>
#ifdef DEBUG
#undef DEBUG
#endif
#ifdef __WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif
using namespace std;
const int mod = 998244353;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
int n;
cin >> n;
vector<long long> a(n), p, b;
auto f3 = [&](long long x) {
static const long long oo = 3e18;
long long l = 1, r = 2000000;
while(l <= r) {
long long t = l + r >> 1, s = t * t * t;
if(s == x) return t;
if(s < x) l = t + 1;
else r = t - 1;
}
if(l * l * l == x) return l;
if(r * r * r == x) return r;
return -1ll;
};
auto f2 = [&](long long x) {
long long l = 1, r = 2000000000;
while(l <= r) {
long long t = l + r >> 1, s = t * t;
if(s == x) return t;
if(s < x) l = t + 1;
else r = t - 1;
}
if(l * l == x) return l;
if(r * r == x) return r;
return -1ll;
};
for (int i = 0; i < n; ++i) {
cin >> a[i];
if(a[i] == 1) continue;
long long x = f3(a[i]);
if(x != -1) p.push_back(x);
else {
x = f2(a[i]);
if(x != -1) {
long long y = f2(x);
if(y != -1) p.push_back(y);
else p.push_back(x);
}
else b.push_back(a[i]);
}
}
for (auto x: b) for (auto y: b) {
long long z = gcd(x, y);
if(z == 1 || z == x || z == y) continue;
p.push_back(z);
if(!z) return 0;
p.push_back(x / z);
p.push_back(y / z);
}
sort(p.begin(), p.end());
p.resize(unique(p.begin(), p.end()) - p.begin());
vector<long long> q;
for (auto x: b) for (auto y: p) if(x % y == 0) q.push_back(x / y);
p.insert(p.end(), q.begin(), q.end());
sort(p.begin(), p.end());
p.resize(unique(p.begin(), p.end()) - p.begin());
vector<int> cnt(p.size(), 0);
b.clear();
for (auto x: a) {
if(x == 1) continue;
bool flag = 0;
for (int i = 0; i < p.size(); ++i) {
if(!p[i]) return 0;
while(x % p[i] == 0) {
++cnt[i];
flag = 1;
x /= p[i];
}
}
if(flag == 0) b.push_back(x);
}
int ans = 1;
for (int x: cnt) ans = (long long) ans * (x + 1) % mod;
sort(b.begin(), b.end());
for (int i = 0; i < b.size(); ++i) {
int j = i;
while(j + 1 < b.size() && b[j + 1] == b[i]) ++j;
ans = (long long) (j - i + 2) * (j - i + 2) * ans % mod;
i = j;
}
cout << ans << endl;
return 0;
}