2. Sieve of Eratosthenes #
Created Tuesday 28 July 2020
- We write all the numbers in a bool array.
- All are true initially.
- We start from 2, mark all its multiples as false.
- Then continue for the rest till √n i.e highest factor.
Tweaks:
- As we go to multiples, we can start from the current one i.e start from i*i
- We can skip a number if number % is multiple of any of the previous numbers. Skip 4 because 2 is already over.
- We go till √n, and not till n. Everything has been covered.