2470. Number of Subarrays With LCM Equal to K 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617class Solution {public: int subarrayLCM(vector<int>& nums, int k) { unsigned int n= nums.size(), ret = 0; for(int i=0;i<n;++i) { unsigned int t = nums[i]; for(int j=i;j<n;j++) { t= lcm(t, nums[j]); if(t==k) ret++; } } return ret; }}; analysis time complexity O(n^2) space complexity O(1)