AkhzarFarhan / HactoberFest-2022

This repository is made for absolute beginners who want to make their first pull request to get eligibility for HactoberFest-2022.
8 stars 150 forks source link

prime numbers using Sieve of Eratosthenes #158

Closed Pratyush-IITBHU closed 2 years ago

Pratyush-IITBHU commented 2 years ago

Hello Sir, This is my C++ code to find the prime numbers up to an input number n using Sieve of Eratosthenes. It is an efficient way to find the prime numbers.

In it we will assign a vector of pairs having the first element as integer and second as bool, second bool element will help us to check whether a number is prime or not.

After that except 2, we will remove all even numbers, and then multiples of other numbers like 3, 5, 7, etc will be assigned false as they are not prime. This assignation of false to the multiples of a number i will start from i*i because, before it, its other multiples will already be falsed by smaller primes