sieve of eratosthenes c 2b 2b code

Solutions on MaxInterview for sieve of eratosthenes c 2b 2b code by the best coders in the world

showing results for - "sieve of eratosthenes c 2b 2b code"
Elisa
26 Oct 2017
1int n;
2vector<bool> is_prime(n+1, true);
3is_prime[0] = is_prime[1] = false;
4for (int i = 2; i <= n; i++) {
5    if (is_prime[i] && (long long)i * i <= n) {
6        for (int j = i * i; j <= n; j += i)
7            is_prime[j] = false;
8    }
9}
10
Ginny
29 Mar 2016
1// C++ program to print all primes smaller than or equal to 
2// n using Sieve of Eratosthenes 
3#include <bits/stdc++.h> 
4using namespace std; 
5
6void SieveOfEratosthenes(int n) 
7{ 
8	// Create a boolean array "prime[0..n]" and initialize 
9	// all entries it as true. A value in prime[i] will 
10	// finally be false if i is Not a prime, else true. 
11	bool prime[n+1]; 
12	memset(prime, true, sizeof(prime)); 
13
14	for (int p=2; p*p<=n; p++) 
15	{ 
16		// If prime[p] is not changed, then it is a prime 
17		if (prime[p] == true) 
18		{ 
19			// Update all multiples of p greater than or 
20			// equal to the square of it 
21			// numbers which are multiple of p and are 
22			// less than p^2 are already been marked. 
23			for (int i=p*p; i<=n; i += p) 
24				prime[i] = false; 
25		} 
26	} 
27
28	// Print all prime numbers 
29	for (int p=2; p<=n; p++) 
30	if (prime[p]) 
31		cout << p << " "; 
32} 
33
34// Driver Program to test above function 
35int main() 
36{ 
37	int n = 30; 
38	cout << "Following are the prime numbers smaller "
39		<< " than or equal to " << n << endl; 
40	SieveOfEratosthenes(n); 
41	return 0; 
42} 
43
Tommaso
04 Jul 2020
1int n;
2vector<char> is_prime(n+1, true);
3is_prime[0] = is_prime[1] = false;
4for (int i = 2; i <= n; i++) {
5    if (is_prime[i] && (long long)i * i <= n) {
6        for (int j = i * i; j <= n; j += i)
7            is_prime[j] = false;
8    }
9}
10
Sara
14 Oct 2017
1#include <iostream>
2const int len = 30;
3int main() {
4   int arr[30] = {0};
5   for (int i = 2; i < 30; i++) {
6      for (int j = i * i; j < 30; j+=i) {
7         arr[j - 1] = 1;
8      }
9   }
10   for (int i = 1; i < 30; i++) {
11      if (arr[i - 1] == 0)
12         std::cout << i << "\t";
13   }
14}
queries leading to this page
sieve of eratosthenes c 2b 2b complexitysieve of eratosthenes c 2b 2b time complexitysieve of eratosthenes c 2b 2b codesieve of eratosthenes c 2b 2bc 2b 2b sieve of eratosthenessieve of eratosthenes c 2b 2b not workingsieve of eratosthenes in c 2b 2bsieve of eratosthenes o 28n 29 c 2b 2bprime sieve c 2b 2bcan you use vector math to increase the speed of sieve of eratosthenesc 2b 2b sieve of eratosthenes o 28n 29sieve of eratosthenes c 2b 2b complexityprime number c 2b 2b less time complexityhw sieve of eratosthenes optmization time in csieve algorithm complexitysimple sieve vs sieve of eratosthenessieve of eratosthenes 0 28n 29 time complexity c implementation geeks for geekssieve of eratosthenes spf c 2b 2bc 2b 2b sieve of eratosthenes codeeratosthenes of sieve c 2b 2bsieve of eratosthenes in 0 28n 29 time complexity c implementation geeks for geekssieve eratosthenecomplexity of prime sievesieve of eratosthenes algorithmsieve of eratosthenes complexity proofsieve of eratosthenes in logn timehow to get the prime number in c 2b 2b where time complexity is 0 28log n 29seive of errethros in kotlinreverse a list in python time complexitysieve of eratosthenes in cppreversed in python time complexitysieve of eratosthenes c 2beratosthenes sieve in c 2b 2bsieve of eratosthenes time complexity codesieve of eratosthenes code in c 2b 2bprime sieve complexitysieve of eratosthenes c 2b 2b o 28n 29prime number under n is what time complexitysieve of eratosthenes time complexityleast time complexity algorithm to find prime numberssieve of eratosthenes cppprime factors using sieve of eratosthenestime complexity sieve of eratosthenessieve of eratosthenes in c 2b 2b programmodified sievesieve of eratosthenes o 281 29cpp compare 2 unordered set time complexitysieve of eratosthenes c 2b 2b cp algorithmstime complexity of sieve of eratosthenessieve function in c 2b 2bseive for prime numbers less than nsieve of eratosthenes c 2b 2b code