Ctrl K

Products Free of Squares

Medium
You are given an array values of positive integers. A number is *square-free* if no perfect square other than 1 divides it (for example, 30 is square-free, while 12 = 4 · 3 is not). A pick is a non-empty set of positions in the array. Two picks are different if their sets of positions differ, even when the values at those positions are the same. Return the number of picks whose product is square-free. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
values=[2, 6, 9, 5] → 5.0

9 = 3² is out at once. From 2, 6 and 5 the valid picks are {2}, {6}, {5}, {2, 5}, {6, 5}; {2, 6} gives 12, which is divisible by 4. That makes 5.

Example 2
values=[1, 1, 7] → 7.0

Ones never cause trouble, so every non-empty pick works: 2³ − 1 = 7.

Example 3
values=[4, 8, 25] → 0.0
Constraints
  • 1 ≤ len(values) ≤ 1000
  • 1 ≤ values[i] ≤ 30
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFewest Lines Through the Dots MediumTwo Groups With the Same Average HardSquare-Sum Chains HardProduct of Distinct Primes HardBump Numbers to Fit the Divisors Hard
loading Python…
Input
values=[2, 6, 9, 5]
Expected
5.0

Run checks the first 3 tests in your browser. Submit checks all 60 tests on the server, hidden ones included.