Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sieve Of Eratosthenes
#include <bits/stdc++.h> #include <iostream> int main() { int n = 50; std::vector<int> SieveOfEratosthenes(int n); bool prime[n + 1]; memset(prime, true, sizeof(prime)); std::vector<int> res; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) res.push_back(p); for (int elem : res) { std::cout << elem << " "; } }
run
|
edit
|
history
|
help
0
PyramidTransitionMatrix_recursive
FindKthElementDivideConquer
Day3
MAC
Sort row sorted matrix
Breakfast Menu
completeBubbleSort
Variadic template example
Sorting Array
UB mutex lock