Tag Archives: Prime Number

Least prime factor of numbers till n

Given a number n, print least prime factors of all numbers from 1 to n. The least prime factor of an integer n is the… Read More »

Print all prime factors and their powers

Given a number N, print all its unique prime factors and their powers in N. Examples: Input: N = 100 Output: Factor Power 2 2… Read More »

Count Divisors of Factorial

Given a number n, count total number of divisors of n!. Examples: Input : n = 4 Output: 24 4! is 24. Divisors of 24… Read More »

Palindromic Primes

A palindromic prime (sometimes called a palprime) is a prime number that is also a palindromic number. Given a number n, print all palindromic primes… Read More »

Almost Prime Numbers

A k-Almost Prime Number is a number having exactly k prime factors (not necessary distinct). For example, 2, 3, 5, 7, 11 ….(in fact all… Read More »

Remove duplicates from an array of small primes

Given an array of primes such that the range of primes is small. Remove duplicates from the array. Examples: Input: arr[] = {3, 5, 7,… Read More »

Quick ways to check for Prime and find next Prime in Java

Many programming contest problems are somehow related Prime Numbers. Either we are required to check Prime Numbers, or we are asked to perform certain functions… Read More »

MAQ Software Interview Experience | Set 12 (Written Test)

I got interviewed by MAQ via Skype and they asked me below three question and the duration was 20 min :- 1. Write a program… Read More »

Sieve of Atkin

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

Sieve of Sundaram to print all primes smaller than n

Given a number n, print all primes smaller than or equal to n. Examples: Input: n = 10 Output: 2, 3, 5, 7 Input: n… Read More »

Wilson’s Theorem

Wilson’s theorem states that a natural number p > 1 is a prime number if and only if (p – 1) ! ≡ -1 mod… Read More »

Primality Test | Set 3 (Miller–Rabin)

Given a number n, check if it is prime or not. We have introduced and discussed School and Fermat methods for primality testing. Primality Test… Read More »

Euclid’s lemma

We are given two numbers x and y. We know that a number p divides their product. Can we say for sure that p also… Read More »

Segmented Sieve

Given a number n, print all primes smaller than n. For example, if the given number is 10, output 2, 3, 5, 7.  Recommended: Please… Read More »

Walmart Lab Interview Experience | Set 8 (Off-Campus 3 Years Experience)

Round 1 (Coding round): 1) Range [L, R] is given. Need to find what is the maximum repeating digit in prime numbers between L and… Read More »