结论:最小公倍数lcm(x,y)=x*y/gcd(x,y)
暴力枚举即可。
- class Solution {
- public:
- int get(int x,int y){
- return x*y/__gcd(x,y);
- }
- int subarrayLCM(vector<int>& a, int k) {
- int ans=0;
- int n=a.size();
- for(int i=0;i
- int g=a[i];
- for(int j=i;j
- g=get(g,a[j]);
- if(g==k) ans++;
- if(g>k) break;
- }
- }
- return ans;
- }
- };
时间复杂度:O(
)
空间复杂度:O(1)
-
相关阅读:
Nginx替代产品-Tengine健康检测
QT开发之串口通信(四)
【C语言 模拟实现strcat函数】
k8s的服务Service暴露应用
Vue3+ts(day07:pinia)
sql多表查询,嵌套查询,函数查询
npm常见操作
The Journey from Idea to Production: A Product Designer‘s Perspective
SolidWorks二次开发 API-SOLIDWORKS Simulation分析参数修改
计算机毕业设计Java惠购网站(源码+系统+mysql数据库+lw文档)
-
原文地址:https://blog.csdn.net/aaa7888210/article/details/127834308