Given an array with N elements, task is to find the count of factors of a number X which is product of all array elements.
Input : 5 5 Output : 3 5 * 5 = 25, the factors of 25 are 1, 5, 25 whose count is 3 Input : 3 5 7 Output : 8 3 * 5 * 7 = 105, the factors of 105 are 1, 3, 5, 7, 15, 21, 35, 105 whose count is 8
Method 1 (Simple but causes overflow)
1. Multiply all the elements of the array.
2. Count divisors in the number obtained after multiplication.
Method 2 (Avoids overflow)
1. Find maximum element in array
1. Find prime numbers smaller than the maximum element
3. Find the number of overall occurrences of each prime factor in whole array by traversing all array elements and finding their prime factors. We use hashing to count occurrences.
4. Let the counts of occurrences of prime factors be a1, a2, …aK, if we have K distinct prime factors, then the answer will be: (a1+1)(a2+1)(…)*(aK+1).
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Sum of multiplication of triplet of divisors of a number
- Count Divisors of n in O(n^1/3)
- Count Divisors of Factorial
- Check if count of divisors is even or odd
- Count divisors of n that have at-least one digit common with n
- Count all perfect divisors of a number
- Count total divisors of A or B in a given range
- C Program to Check if count of divisors is even or odd
- Count of numbers below N whose sum of prime divisors is K
- Count the numbers < N which have equal number of divisors as K
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Java Program to Check if count of divisors is even or odd
- Count of divisors having more set bits than quotient on dividing N
- Maximum count of common divisors of A and B such that all are co-primes to one another
- Numbers in range [L, R] such that the count of their divisors is both even and prime
Improved By : nitin mittal