Number of digits in N factorial to the power N

Given a positive integer N, we have to find the total number of digits in the factorial of N raised to the power N, i.e,… Read More »

Product of first N factorials

Given a number N. Find the product of first N factorials modulo 1000000007. Constraints: 1 ≤ N ≤ 1e6 Examples: Input : 3 Output :… Read More »

Sum of series 1*1*2! + 2*2*3! + ……..+ n*n*(n+1)!

Given n, we need to find sum of 1*1*2! + 2*2*3! + ……..+ n*n*(n+1)! Examples: Input: 1 Output: 2 Input: 3 Output: 242 We may… Read More »

Count numbers formed by given two digit with sum having given digits

Given a, b and N(1 to 106). Task is to count the numbers formed by digits a and b exactly of a length N such… Read More »

Program to calculate value of nCr

Following are common definition of Binomial Coefficients. A binomial coefficient C(n, k) can be defined as the coefficient of X^k in the expansion of (1… Read More »

Ways to multiply n elements with an associative operation

Given a number n, find the number of ways to multiply n elements with an associative operation. Examples : Input : 2 Output : 2… Read More »

Generate a list of n consecutive composite numbers (An interesting method)

Given a number n, generate a list of n composite numbers. Examples: Input : 5 Output : 122, 123, 124, 125 Input : 10 Output… Read More »

First digit in factorial of a number

Given a positive integer n, find the first digit in its factorial. Examples : Input : n = 5 Output : 1 Factorial of 5… Read More »

Expressing factorial n as sum of consecutive numbers

Given two numbers N and M. Find the number of ways in which factorial N can be expressed as a sum of two or more… Read More »

Power of a prime number ‘r’ in n!

Given an integer n, find the power of a given prime number(r) in n! Examples : Input : n = 6 r = 3 Factorial… Read More »

Sum of largest divisible powers of p (a prime number) in a range

Given a range [L, R], and a prime number P. We are required to find the sum of the highest power of P in all… Read More »

Count maximum-length palindromes in a String

Given a string, count how many maximum-length palindromes are present.(It need not be a substring) Examples: Input : str = “ababa” Output: 2 Explanation :… Read More »

Lexicographic rank of a string with duplicate characters

Given a string s that may have duplicate characters. Find out the lexicographic rank of s. s may consist lower as well as upper case… Read More »

Find maximum power of a number that divides a factorial

Given two numbers, fact and n, find the largest power of n that divides fact! (Factorial of fact). Examples: Input : fact = 5, n… Read More »

Trailing number of 0s in product of two factorials

Given two integer N or M find the number of zero’s trailing in product of factorials (N!*M!)? Examples: Input : N = 4, M =… Read More »