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 firstname.lastname@example.org. 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)
- Check if count of divisors is even or odd
- Count Divisors of Factorial
- 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 divisors of n that have at-least one digit common with n
- Java Program to Check if count of divisors is even or odd
- Count the numbers < N which have equal number of divisors as K
- Count of divisors having more set bits than quotient on dividing N
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Count number of integers less than or equal to N which has exactly 9 divisors
- Count elements in the given range which have maximum number of divisors
- Program to find count of numbers having odd number of divisors in given range
Improved By : nitin mittal