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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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 of Fibonacci divisors of a given number
- 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
- Count of the non-prime divisors of a given number
- Count of numbers below N whose sum of prime divisors is K
- Count all perfect divisors of a number
- Count total divisors of A or B in a given range
- 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
- Count of divisors having more set bits than quotient on dividing N
- 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 all pairs of divisors of a number N whose sum is coprime with N
Improved By : nitin mittal