We can calculate the prime factorization of a number “n” in O(sqrt(n)) as discussed here. But O(sqrt n) method times out when we need to answer multiple...

Share

Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.
Example:
Input : n =10
Output : 2 3 5 7
Input : n = 20
...

Share

Given a number n, print all primes smaller than or equal to n.
Examples:
Input: n = 10
Output: 2, 3, 5, 7
Input: n = 20
Output: 2, 3, 5, 7, 11, 13, 17, 19
We have ...

Share

Given a number n, print all primes smaller than n. For example, if the given number is 10, output 2, 3, 5, 7.
Recom...

Share

The classical Sieve of Eratosthenes algorithm takes O(N log (log N)) time to find all prime numbers less than N. In this article, a modified Sieve is discussed that w...

Share

Given a limit, print all primes smaller than or equal to the given limit.
Examples :
Input: limit = 10
Output: 2, 3, 5, 7
Input: limit = 20
Output: 2, 3, 5, 7, 11...

Share