Category: factorial

Find subfactorial of a number

Given an integer N, the task is to find the subfactorial of the number represented as !N. The subfactorial of a number is defined using below recurrence relation of a number N:!N = (N-1) [ !(N-2) + !(N-1) ]where !1 = 0 and !0 = 1Some of the subfactorials are:n012345678910111213!n10129442651, 85414, 833133, 4961, 334, 96114, […]

Continue Reading

Exponential factorial of N

Exponential factorial of N Given a positive integer N, the task is to print the Exponential factorial of N. Since the output can be very large, print the answer modulus 1000000007. Examples:  Input: N = 4  Output: 262144   Input: N = 3  Output: 9  Approach: The given problem can be solved based on the following observations: The exponential […]

Continue Reading

Prefix Factorials of a Prefix Sum Array

Given an array arr[] consisting of N positive integers, the task is to find the prefix factorials of a prefix sum array of the given array i.e.,  .Examples:Input: arr[] = {1, 2, 3, 4}Output: 1 6 720 3628800Explanation:The prefix sum of the given array is {1, 3, 6, 10}. Therefore, prefix factorials of the obtained […]

Continue Reading

Count prime factors of N!

Count prime factors of N! Given an integer N, the task is to count the number of prime factors of N!. Examples: Input: N = 5Output: 3Explanation: Factorial of 5 = 120. Prime factors of 120 are {2, 3, 5}. Therefore, the count is 3. Input: N = 1Output: 0 Naive Approach: Follow the steps […]

Continue Reading