<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:
        c = []
        if not k & 1:
            c.append([2,1])
            while not k & 1:
                k >>= 1
                c[-1][1] *= 2
        p = 3
        while k > 1:
            if not k % p:
                c.append([p,1])
                while not k % p:
                    c[-1][1] *= p
                    k //= p
            p += 2
        d = {p:[] for p,q in c}
        avoid = []
        for i in range(len(nums)):
            num = nums[i]
            temp = []
            for p,q in c:
                if not num % p:
                    if not num % q:
                        num //= q
                        temp.append(p)
                    else:
                        while not num % p:
                            num //= p
            if num == 1:
                for p in temp:
                    d[p].append(i)
            else:
                avoid.append(i)
        
        n = len(nums)
        l = {p:[0] for p in d}
        for p in d:
            temp = [0] * n
            for i in d[p]:
                temp[i] = 1
            for i in range(n):
                l[p].append(temp[i] + l[p][-1])
        t = [0]
        temp = [0] * n
        for i in avoid:
            temp[i] = 1
        for i in range(n):
            t.append(temp[i] + t[-1])
        ans = 0
        for j in range(n + 1):
            for i in range(j):
                if t[j] == t[i] and all(l[p][j] > l[p][i] for p in l):
                    ans += 1
        return ans
        




        return 0
555