2470. Number of Subarrays With LCM Equal to K Medium

@problem@discussion
#Array#Math#Number Theory



1/**
2 * [2470] Number of Subarrays With LCM Equal to K
3 *
4 * Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k.
5 * A subarray is a contiguous non-empty sequence of elements within an array.
6 * The least common multiple of an array is the smallest positive integer that is divisible by all the array elements.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: nums = [3,6,2,7,1], k = 6
11 * Output: 4
12 * Explanation: The subarrays of nums where 6 is the least common multiple of all the subarray's elements are:
13 * - [<u>3</u>,<u>6</u>,2,7,1]
14 * - [<u>3</u>,<u>6</u>,<u>2</u>,7,1]
15 * - [3,<u>6</u>,2,7,1]
16 * - [3,<u>6</u>,<u>2</u>,7,1]
17 * 
18 * <strong class="example">Example 2:
19 * 
20 * Input: nums = [3], k = 2
21 * Output: 0
22 * Explanation: There are no subarrays of nums where 2 is the least common multiple of all the subarray's elements.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= nums.length <= 1000
28 * 	1 <= nums[i], k <= 1000
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/number-of-subarrays-with-lcm-equal-to-k/
34// discuss: https://leetcode.com/problems/number-of-subarrays-with-lcm-equal-to-k/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn subarray_lcm(nums: Vec<i32>, k: i32) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_2470() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.