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
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