Distinct Prime Factors of Product of Array
Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.
Note that:
- A number greater than
1is called prime if it is divisible by only1and itself. - An integer
val1is a factor of another integerval2ifval2 / val1is an integer.
Example 1
Input
nums = [2,4,3,7,10,6]Output
4The product is 10080 = 2^5 * 3^2 * 5 * 7, so there are 4 distinct prime factors.
Example 2
Input
nums = [2,4,8,16]Output
1The product is 1024 = 2^10, so there is 1 distinct prime factor.
Constraints
- 1 <= nums.length <= 10^4
- 2 <= nums[i] <= 1000