Class Solution
-
- All Implemented Interfaces:
public final class Solution2521 - 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 ofnums.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: 4
Explanation: The product of all the elements in nums is: 2 \* 4 \* 3 \* 7 \* 10 \* 6 = 10080 = 2<sup>5</sup> \* 3<sup>2</sup> \* 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 = 2<sup>10</sup>.
There is 1 distinct prime factor so we return 1.
Constraints:
<code>1 <= nums.length <= 10<sup>4</sup></code>
2 <= nums[i] <= 1000
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classSolution.Companion
-
Field Summary
Fields Modifier and Type Field Description public final static Solution.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerdistinctPrimeFactors(IntArray nums)-
-
Method Detail
-
distinctPrimeFactors
final Integer distinctPrimeFactors(IntArray nums)
-
-
-
-