Tag Archives: sieve

Count all perfect divisors of a number

Given a number n, count total perfect divisors of n. Perfect divisors are those divisors which are square of some integer. For example a perfect divisor of 8 is 4. Input : n = 16 Output : 3 Explanation : There are only 5 divisor of 16: 1, 2, 4, 8, 16. Only three of… Read More »

Sieve of Eratosthenes in 0(n) time complexity

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 works in O(N) time. Example : Given a number N, print all prime numbers smaller than N Input : int N = 15 Output : 2… Read More »