文章
3
粉丝
0
获赞
6
访问
257
暴力循环,循环到数组最大值会超时,但循环到100即可全对,为何
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
vector<int> v;
while(t--){
int n;
cin>>n;
v.push_back(n);
}
sort(v.begin(),v.end());
int max=v[v.size()-1];
bool x=true;
for(int i=2;i<=100;i++){
for(auto it=v.begin();it!=v.end()-1;it++){
if(*it%i!=*(it+1)%i)x=false;
}
if(x){
cout<<i<<" ";
}
}
}
登录后发布评论
暂无评论,来抢沙发