From 361cbf6eaa02b5a42d189c4afe1e6bf8a87ca0e6 Mon Sep 17 00:00:00 2001 From: Shivam Kumar Pathak <31039145+pathakcodes@users.noreply.github.com> Date: Wed, 23 Oct 2019 23:06:44 +0530 Subject: [PATCH] Added code of Sieve for finding prime numbers. --- seiveofErssthones.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 seiveofErssthones.cpp diff --git a/seiveofErssthones.cpp b/seiveofErssthones.cpp new file mode 100644 index 0000000..eddfa67 --- /dev/null +++ b/seiveofErssthones.cpp @@ -0,0 +1,58 @@ +/* +coded by - PATHAKCODES +AIT PUNE , INDIA + +"The Key is not will to win ......everybody has that " +"It is will to prepare that is important" + + +*/ + + +#include + +using namespace std ; + +#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); +#define endl "\n" +#define ll long long +#define pb push_back +const ll n = 1000000 ; + + + + +int main () +{ + IOS + #ifndef ONLINE_JUDGE + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); + #endif + +ll prime[n+1] ; + for(int i = 0 ; i <= n;i++) + { + prime[i] = 1 ; + + } + + prime[0] = 0 ; + prime[1] = 0 ; + +for(int j = 2 ; j<= sqrt(n) ; j++) +{ + if(prime[j] == 1) + { + for(int i = 2 ; i*j < n ; i++) + prime[i*j] = 0 ; + } +} + + +for (int i = 0; i < 22; ++i) +{ + cout << i << " " << prime[i] << endl ; +} + +} \ No newline at end of file