##
No of Factors of n!
June 25, 2016

Given a positive integer n, find the no of factors in n! where n

June 25, 2016

Given a positive integer n, find the no of factors in n! where n

January 16, 2016

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, 13, 17, 19 We have discussed below algorithms for the above task. Sieve of Eratosthenes Sieve of Sundaram The sieve of… Read More »

January 12, 2016

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 discussed Sieve of Eratosthenes algorithm for the above task. Below is Sieve of Sundaram algorithm. printPrimes(n) [Prints… Read More »

December 16, 2015

Given a large number n and a prime p, how to efficiently compute n! % p? Examples: Input: n = 5, p = 13 Output: 3 5! = 120 and 120 % 13 = 3 Input: n = 6, p = 11 Output: 5 6! = 720 and 720 % 11 = 5 A Naive… Read More »

In this post “Important top 10 algorithms and data structures for competitive coding “. Topics : Graph algorithms Dynamic programming Searching and Sorting: Number theory and Other Mathematical Geometrical and Network Flow Algorithms Data Structures The below links cover all most important algorithms and data structure topics: Graph Algorithms Breadth First Search (BFS) Depth First… Read More »

November 24, 2015

Given a number n, print all primes smaller than n. For example, if the given number is 10, output 2, 3, 5, 7. A Naive approach is to run a loop from 0 to n-1 and check each number for primeness. A Better Approach is use Simple Sieve of Eratosthenes. Problems with Simple Sieve: The… Read More »

November 20, 2015

Given a range [low..high], print the smallest twin numbers in given range (low and high inclusive). Two numbers are twins if they are primes and there difference is 2.

November 14, 2015

Euler’s Totient function Φ(n) for an input n is count of numbers in {1, 2, 3, …, n} that are relatively prime to n, i.e., the numbers whose GCD (Greatest Common Divisor) with n is 1.

July 27, 2012

Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if n is 10, the output should be “2, 3, 5, 7”. If n is 20, the output should be “2, 3, 5, 7, 11, 13, 17, 19”.