超详细题解题解(含注释)
2025-11-25 22:08:12
发布于:广东
6阅读
0回复
0点赞
思路:
把全部因数都枚举一遍,最后用打擂法求出最大值
代码:
#include<bits/stdc++.h>//万能头
using namespace std;
int a[114514];//大小有点那个
int main(){
int n,Max = -1;//这里要注意一点,如果定义了max,可能会报错,所以m用大写
cin >> n;//输入数组长度
for(int i = 1;i <= n;i++){
cin >> a[i];//输入数组
}
int cnt;//记和
for(int i = 2;i <= 1000;i++){
cnt = 0;//每轮都要清空
for(int j = 1;j <= n;j++){
if(a[j] % i == 0){
cnt++;//如果a[j]有因数i,那cnt就加一个
}
}
if(cnt > Max){
Max = cnt;//打擂法
}
}
cout << Max;//输出
return 0;//完美收官
}
这里空空如也







有帮助,赞一个