java.lang.Object
g2401_2500.s2470_number_of_subarrays_with_lcm_equal_to_k.Solution

public class Solution extends Object
2470 - Number of Subarrays With LCM Equal to K.<p>Medium</p> <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&rsquo;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><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,6,2,7,1], k = 6</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The subarrays of nums where 6 is the least common multiple of all the subarray&rsquo;s elements are:</p> <ul> <li>[<ins> <strong>3</strong> </ins>,<ins> <strong>6</strong> </ins>,2,7,1]</li> <li>[<ins> <strong>3</strong> </ins>,<ins> <strong>6</strong> </ins>,<ins> <strong>2</strong> </ins>,7,1]</li> <li>[3,<ins> <strong>6</strong> </ins>,2,7,1]</li> <li>[3,<ins> <strong>6</strong> </ins>,<ins> <strong>2</strong> </ins>,7,1]</li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [3], k = 2</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There are no subarrays of nums where 2 is the least common multiple of all the subarray&rsquo;s elements.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1000</code></li> <li><code>1 <= nums[i], k <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • subarrayLCM

      public int subarrayLCM(int[] nums, int k)