Tag Archives: sieve

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 »

Find two prime numbers with given sum

Given an even number (greater than 2 ), print two prime numbers whose sum will be equal to given number. There may be several combinations possible. Print only first such pair. An interesting point is, a solution always exist according to Goldbach’s conjecture. Examples: Input: n = 74 Output: 3 71 Input : n =… Read More »

Super Prime

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. First few Super-Primes are 3, 5, 11 and 17. The task is to print all the Super-Primes less than or equal to the given positive integer N. Examples: Input: 7… Read More »

Mersenne Prime

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 is of the form 2k-1 where k is an integer greater than or equal to 2. First few Mersenne Primes are 3, 7, 31 and 127. The task is print… Read More »

Circular primes less than n

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 prime numbers. Examples: 79 is a circular prime. as 79 and 97 are prime numbers. But 23 is not a circular prime. as 23 is prime but 32 is not… Read More »

Sphenic Number

A Sphenic Number is a positive integer n which is product of exactly three distinct primes. The first few sphenic numbers are 30, 42, 66, 70, 78, 102, 105, 110, 114, … Given a number n, determine whether it is a Sphenic Number or not. Examples: Input : 30 Output : Yes Explanation : 30… Read More »

Equidigital Numbers

A number n is called Equidigital if the number of digits in the prime factorization of n (including powers) is same as number of digits in n. For example 16 is an Equidigital number as its prime factorization is 2^4 and its prime factorization has total two digits (2 and 4) which is same as… Read More »

Emirp numbers

Emirp is the word “prime” spelled backwards, and it refers to a prime number that becomes a new prime number when you reverse its digits. Emirps do not include palindromic primes (like 151 or 787) nor 1-digit primes like 7. 107, 113, 149, and 157 – reverse them and you’ve got a new prime number… Read More »