<p>Given an array <code>nums</code> of&nbsp;positive integers. Your task is to select some subset of <code>nums</code>, multiply each element by an integer and add all these numbers.&nbsp;The array is said to be&nbsp;<strong>good&nbsp;</strong>if you can obtain a sum of&nbsp;<code>1</code>&nbsp;from the array by any possible subset and multiplicand.</p>

<p>Return&nbsp;<code>True</code>&nbsp;if the array is <strong>good&nbsp;</strong>otherwise&nbsp;return&nbsp;<code>False</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [12,5,7,23]
<strong>Output:</strong> true
<strong>Explanation:</strong> Pick numbers 5 and 7.
5*3 + 7*(-2) = 1
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [29,6,10]
<strong>Output:</strong> true
<strong>Explanation:</strong> Pick numbers 29, 6 and 10.
29*1 + 6*(-3) + 10*(-1) = 1
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,6]
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10^9</code></li>
</ul>

class Solution:
    def isGoodArray(self, nums: List[int]) -> bool:
        # nums: 10^5
        # nums[i] can be up to 10^9
        
        # we want to use a subset of nums to get 1 using a multiplicand
        # no fraction multiplication, but we can subtract

        # ax = b | a -> subset with the independent vectors (prime)
        # x = multiplicand
        # b = 1

        # if we only have multiples of two numbers, then we should see if their gcd is the same
        # computing the gcd for each number is expensive, we could store all seen factors in a set
        nums.sort()
        # O(Nsqrt(M)) M = max(nums)
        # min of nums and did a moduli across all the nums
        # [5, 7, 12 ,23] -> [0, 2, 2, 3]
        # gcd(a, b) > 1 and gcd(b, c) > 1
        # (2, 14) AND (14, 49)
        # [15, 14, 49]
        # time complexity of GCD is
        def gcd(a, b):
            if a == 0:
                return b
            return gcd(b % a, a)
        if 1 in nums:
            return True
        min_num = nums[0]
        gcds = set([min_num])
        for i in range(1, len(nums)):
            for num in gcds:
                if gcd(num, nums[i]) == 1:
                    return True
            gcds.add(gcd(num, nums[i]))
        return False
27600