1
0
Fork 0

Add number/soe.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-05-20 21:39:58 +08:00
parent 9dd10a201d
commit 4e7835f6e5
1 changed files with 15 additions and 0 deletions

15
number/soe.cc Normal file
View File

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