Class Solution
java.lang.Object
g2501_2600.s2521_distinct_prime_factors_of_product_of_array.Solution
public class Solution
extends java.lang.Object
2521 - Distinct Prime Factors of Product of Array.
Medium
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
1
is called prime if it is divisible by only1
and itself. - An integer
val1
is a factor of another integerval2
ifval2 / val1
is an integer.
Example 1:
Input: nums = [2,4,3,7,10,6]
Output: 4
Explanation: The product of all the elements in nums is: 2 * 4 * 3 * 7 * 10 * 6 = 10080 = 25 * 32 * 5 * 7.
There are 4 distinct prime factors so we return 4.
Example 2:
Input: nums = [2,4,8,16]
Output: 1
Explanation: The product of all the elements in nums is: 2 * 4 * 8 * 16 = 1024 = 210.
There is 1 distinct prime factor so we return 1.
Constraints:
1 <= nums.length <= 104
2 <= nums[i] <= 1000
-
Constructor Summary
-
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
distinctPrimeFactors
public int distinctPrimeFactors(int[] nums)
-