- Sieve of Eratosthenes – Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. GFG
- Least prime factor of numbers till n – Given a number n, print least prime factors of all numbers from 1 to n. GFG
Algo: Use Sieve of Eratosthenes logic.
- Print all prime factors of a given number.
1. GFG Divide the number n with n till it’s possible. Then start dividing the number from 3 till sqrt(n) and save/print numbers that divide the number completely.
2. GFG Use Sieve of Eratosthenes logic.
Complexity : O(log n)
All the question can be solved based on the logic and almost similar code from Sieve of Eratosthenes implementation.