# Tag Archives: sieve

## Count pairs with sum as a prime number and less than nApril 9, 2017

Given a positive integer n, count distinct number of pairs (x, y) that satisfy following conditions : (x + y) is a prime number. (x… Read More »

## Count Divisors of n in O(n^1/3)

Given a number n, count all distinct divisors of it. Examples: Input : 18 Output : 6 Divisors of 18 are 1, 2, 3, 6,… Read More »

## Count all perfect divisors of a numberMarch 14, 2017

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… Read More »

## Prime Factorization using Sieve O(log n) for multiple queriesMarch 10, 2017

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… Read More »

## Nearest element with at-least one common prime factorMarch 7, 2017

Given an array arr[], find nearest element for every element such that there is at least one common prime factor. In output, we need to… Read More »

## Number with maximum number of prime factors

Given an integer N. The task is to find a number that is smaller than or equal to N and has maximum prime factors. In… Read More »

## Queries on the sum of prime factor counts in a rangeMarch 1, 2017

There are Q queries. Each query is of the form of L and R. The task is to output sum of number of prime factors… Read More »

## Minimum operations required to remove an arrayFebruary 28, 2017

Given an array of N integers where N is even. There are two kinds of operations allowed on the array. Increase the value of any… Read More »

## k-th prime factor of a given numberJanuary 31, 2017

Given two numbers n and k, print k-th prime factor among all prime factors of n. For example, if the input number is 15 and… Read More »

## Sieve of Eratosthenes in 0(n) time complexityJanuary 22, 2017

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… Read More »

## Find two prime numbers with given sumJanuary 10, 2017

Given an even number (greater than 2 ), print two prime numbers whose sum will be equal to given number. There may be several combinations… Read More »

## Super PrimeJanuary 4, 2017

Super-prime numbers (also known as higher order primes) are the subsequence of prime numbers that occupy prime-numbered positions within the sequence of all prime numbers.… Read More »

## Mersenne PrimeJanuary 3, 2017

Mersenne Prime is a prime number that is one less than a power of two. In other words, any prime is Mersenne Prime if it… Read More »

## Find the highest occurring digit in prime numbers in a rangeDecember 24, 2016

Given a range L to R, the task is to find the highest occurring digit in prime numbers lie between L and R (both inclusive).… Read More »

## Circular primes less than nDecember 21, 2016

Find all circular primes less than given number n. A prime number is a Circular Prime Number if all of its possible rotations are itself… Read More »