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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Sum of multiplication of triplet of divisors of a number
- Count of divisors of product of an Array in range L to R for Q queries
- Check if count of even divisors of N is equal to count of odd divisors
- Queries for Count of divisors of product of an Array in given range | Set 2 (MO's Algorithm)
- Count Divisors of n in O(n^1/3)
- Check if count of divisors is even or odd
- Count Divisors of Factorial
- Count total divisors of A or B in a given range
- Count of numbers below N whose sum of prime divisors is K
- Count all perfect divisors of a number
- Count divisors of n that have at-least one digit common with n
- Count of Fibonacci divisors of a given number
- C Program to Check if count of divisors is even or odd
- Count of the non-prime divisors of a given number
- Java Program to Check if count of divisors is even or odd
Improved By : nitin mittal