-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add files from section2 geekforgeeks
- Loading branch information
1 parent
8715612
commit 0efe563
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int isPrime(int N) { | ||
|
||
if(N <= 1) | ||
return 0; | ||
|
||
for(int i=2; i*i<=N; ++i) | ||
if(N%i==0) | ||
return 0; | ||
|
||
return 1; | ||
} |
20 changes: 20 additions & 0 deletions
20
geekForgeeks/section2_number_theory/sieveOfEratosthenes.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
vector<int> sieveOfEratosthenes(int N){ | ||
|
||
vector<int> sieve(N,1); | ||
vector<int> ans; | ||
sieve[0] = sieve[1] = 0; | ||
|
||
for(int i = 2; i < N; ++i) { | ||
if(sieve[i] == 1) { | ||
ans.push_back(i); | ||
for(int j = i+i; j < N; j+=i) | ||
sieve[j] = 0; | ||
} | ||
} | ||
|
||
return ans; | ||
|
||
} |