2572. Count the Number of Square-Free Subsets Medium
1/**
2 * [2572] Count the Number of Square-Free Subsets
3 *
4 * You are given a positive integer 0-indexed array nums.
5 * A subset of the array nums is square-free if the product of its elements is a square-free integer.
6 * A square-free integer is an integer that is divisible by no square number other than 1.
7 * Return the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 10^9 + 7.
8 * A non-empty subset of nums is an array that can be obtained by deleting some (possibly none but not all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.
9 *
10 * <strong class="example">Example 1:
11 *
12 * Input: nums = [3,4,4,5]
13 * Output: 3
14 * Explanation: There are 3 square-free subsets in this example:
15 * - The subset consisting of the 0^th element [3]. The product of its elements is 3, which is a square-free integer.
16 * - The subset consisting of the 3^rd element [5]. The product of its elements is 5, which is a square-free integer.
17 * - The subset consisting of 0^th and 3^rd elements [3,5]. The product of its elements is 15, which is a square-free integer.
18 * It can be proven that there are no more than 3 square-free subsets in the given array.
19 * <strong class="example">Example 2:
20 *
21 * Input: nums = [1]
22 * Output: 1
23 * Explanation: There is 1 square-free subset in this example:
24 * - The subset consisting of the 0^th element [1]. The product of its elements is 1, which is a square-free integer.
25 * It can be proven that there is no more than 1 square-free subset in the given array.
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= nums.length <= 1000
31 * 1 <= nums[i] <= 30
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/count-the-number-of-square-free-subsets/
37// discuss: https://leetcode.com/problems/count-the-number-of-square-free-subsets/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn square_free_subsets(nums: Vec<i32>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2572() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.