1
0
Fork 0

Add number/factcount.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-05-29 19:46:37 +08:00
parent f8e979f114
commit 52bc203f6a
1 changed files with 25 additions and 0 deletions

25
number/factcount.cc Normal file
View File

@ -0,0 +1,25 @@
pair<vector<int>, vector<int>> factcount(int n) {
vector<bool> not_prime(n + 1);
vector<int> res(n + 1), num(n + 1);
vector<int> primes;
res[1] = 1;
for (int i = 2; i <= n; ++i) {
if (not not_prime[i]) {
res[i] = 2;
num[i] = 1;
primes.emplace_back(i);
}
for (auto&& x : primes) {
if (i * x > n) break;
not_prime[i * x] = 1;
if (i % x == 0) {
num[i * x] = num[i] + 1;
res[i * x] = res[i] / num[i * x] * (num[i * x] + 1);
break;
}
num[i * x] = 1;
res[i * x] = res[i] * 2;
}
}
return {primes, res};
}