E——小苯的等比数列(错误代码已更新)
首先需要使用map统计每个元素出现次数,找到q为1的最大值,接下来枚举每个元素,在枚举公比q,q满足 a[i]*pow(q,ans) < maxx(最大项)。
#include<bits/stdc++.h>
typedef long long ll;
#define int long long
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
void solve(){
int n;
cin>>n;
vector<int> a(n+1);
map<int,int> mp;
int maxx = 0; //最大元素
for (int i = 1; i <= n; ++i) {
cin>>a[i];
mp[a[i]]++;
maxx = max(maxx,a[i]);
}
int ans = 0;
for (auto i : mp) { //q为1的情况
ans = max(ans,i.second);
}
for (int i = 1;i <= n;i++){ //枚举元素(第一项)
for(int j = 2; a[i] * pow(j,ans) <= maxx;j++){ //以a[i]为首项j为公比的尾项一定小于maxx
ll now = j,cnt = 1;
while(mp[a[i]*now] && a[i]*now <= maxx){
cnt++; //当前公比下数量加一
now *= j; //跟新q
}
ans = max(cnt,ans); //比较最大值
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin>>t;
while(t--){
solve();
}
return 0 ;
}