<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of <strong>subarrays</strong> of </em><code>nums</code><em> where the least common multiple of the subarray&#39;s elements is </em><code>k</code>.</p>

<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>

<p>The <strong>least common multiple of an array</strong> is the smallest positive integer that is divisible by all the array elements.</p>

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

<pre>
<strong>Input:</strong> nums = [3,6,2,7,1], k = 6
<strong>Output:</strong> 4
<strong>Explanation:</strong> The subarrays of nums where 6 is the least common multiple of all the subarray&#39;s elements are:
- [<u><strong>3</strong></u>,<u><strong>6</strong></u>,2,7,1]
- [<u><strong>3</strong></u>,<u><strong>6</strong></u>,<u><strong>2</strong></u>,7,1]
- [3,<u><strong>6</strong></u>,2,7,1]
- [3,<u><strong>6</strong></u>,<u><strong>2</strong></u>,7,1]
</pre>

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

<pre>
<strong>Input:</strong> nums = [3], k = 2
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no subarrays of nums where 2 is the least common multiple of all the subarray&#39;s elements.
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
	<li><code>1 &lt;= nums[i], k &lt;= 1000</code></li>
</ul>

class Solution:
    def subarrayLCM(self, nums: List[int], k: int) -> int:
        # if k == 1:
            
            # return len(nums) * (len(nums)+1) // 2
        i = 0
        ans = 0
        chunk = []
        while i < len(nums):
            # print(chunk)
            
            while i < len(nums) and k % nums[i]:
                i += 1
            lcm = 1
            chunk = []
            start1 = i
            while i < len(nums) and not k % nums[i]:
                # start1 = i
                while i < len(nums) and (not k % nums[i]) and lcm != k:
                    lcm = lcm * nums[i] // math.gcd(lcm, nums[i])
                    print('lcm: ', lcm, 'i: ', i)
                    i += 1
                if lcm == k:
                    if k != 1:
                        i -= 1
                    # print(i-1)
                    chunk.append([0, i]) # end
                    lcm = 1
                    prev = lcm
                    while start1 <= i < len(nums) and lcm != k:
                        prev = lcm
                        print('prev: ', prev, 'start1: ', start1, 'i: ', i)
                        lcm = lcm * nums[i] // math.gcd(lcm, nums[i])
                        i -= 1
                    if lcm == k:
                        if k != 1:
                            i += 1
                        print('start1: ', start1, 'i: ', i)
                        chunk[-1][0] = i - start1 + 1
                        print(i - start1 + 1)
                        lcm = prev
                        print('lcm: ', lcm)
                        start1 = i + 1 # if k != 1 else i + 1 
                        i = chunk[-1][1] + 1
                        print(i)
            print(chunk)   
            ans += sum(u*(i-v) for u, v in chunk) if k!=1 else sum(u*(i-v) for u, v in chunk)   
        return ans
64