Skip to content

Commit

Permalink
add files from section2 geekforgeeks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanashii76 committed Sep 28, 2024
1 parent 8715612 commit 0efe563
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions geekForgeeks/section2_number_theory/primeNumber.cpp
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 geekForgeeks/section2_number_theory/sieveOfEratosthenes.cpp
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;

}

0 comments on commit 0efe563

Please sign in to comment.