结论:最小公倍数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)
-
相关阅读:
LC:最大子数组和
采用CNN-LSTM与迁移学习的虚假评论检测
【数据结构】二叉树的基本概念
机器学习 | MATLAB实现支持向量机分类ClassificationSVM参数设定
Go 语言图片处理简明教程
【计算机毕业设计】2.酒店预订管理系统
一文搞懂 Promise 新 Api allSettled 的用法和 all 区别,以及如何在不支持新特性的环境下实现一个 Polyfill
Mysql - 分库分表
PyTorch中DistributedDataParallel使用笔记
Vm软件安装_链接相机
-
原文地址:https://blog.csdn.net/aaa7888210/article/details/127834308