Class Solution
-
- All Implemented Interfaces:
public final class Solution
1994 - The Number of Good Subsets\.
Hard
You are given an integer array
nums
. We call a subset ofnums
good if its product can be represented as a product of one or more distinct prime numbers.For example, if
nums = [1, 2, 3, 4]
:
Return the number of different good subsets in
nums
modulo <code>10<sup>9</sup> + 7</code>.A subset of
nums
is any array that can be obtained by deleting some (possibly none or all) elements fromnums
. Two subsets are different if and only if the chosen indices to delete are different.Example 1:
Input: nums = 1,2,3,4
Output: 6
Explanation: The good subsets are:
1,2: product is 2, which is the product of distinct prime 2.
1,2,3: product is 6, which is the product of distinct primes 2 and 3.
1,3: product is 3, which is the product of distinct prime 3.
2: product is 2, which is the product of distinct prime 2.
2,3: product is 6, which is the product of distinct primes 2 and 3.
3: product is 3, which is the product of distinct prime 3.
Example 2:
Input: nums = 4,2,3,15
Output: 5
Explanation: The good subsets are:
2: product is 2, which is the product of distinct prime 2.
2,3: product is 6, which is the product of distinct primes 2 and 3.
2,15: product is 30, which is the product of distinct primes 2, 3, and 5.
3: product is 3, which is the product of distinct prime 3.
15: product is 15, which is the product of distinct primes 3 and 5.
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
1 <= nums[i] <= 30
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
numberOfGoodSubsets(IntArray nums)
-
-
Method Detail
-
numberOfGoodSubsets
final Integer numberOfGoodSubsets(IntArray nums)
-
-
-
-