Hello Sir,
this is my C++ code to to find the prime factors of an input number n using Sieve of Eratosthenes. It is an efficient way to find the prime factors.
In this we will first find all prime numbers before n, then 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
by this, we will find all primes before n and then we will one by one check if that number is divisible by those primes, if it is divisible, we will start the checking loop again from the beginning because it is possible that number n is again divisible by that same prime number
At last, we will show all primes that perfectly divided n
Hello Sir, this is my C++ code to to find the prime factors of an input number n using Sieve of Eratosthenes. It is an efficient way to find the prime factors.
In this we will first find all prime numbers before n, then 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
by this, we will find all primes before n and then we will one by one check if that number is divisible by those primes, if it is divisible, we will start the checking loop again from the beginning because it is possible that number n is again divisible by that same prime number
At last, we will show all primes that perfectly divided n