#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5;
struct point
{
LL g,p;
point(int a,int b):g(a),p(b) {}
};
int n,t;
LL a[maxn+50];
vector<point>m;
LL gcd(LL a,LL b)
{
return b==0?a:gcd(b,a%b);
}
int cmp(point a,point b)
{
if(a.g==b.g) return a.p<b.p;
else return a.g<b.g;
}
int main()
{
scanf("%d",&t);
while(t--)
{
m.clear();
LL ans=0;
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%lld",&a[i]);
for(int j=0; j<n; j++)
{
m.push_back(point(0,j));
for(int k=0; k<m.size(); k++)
m[k].g=gcd(m[k].g,a[j]);
sort(m.begin(),m.end(),cmp);
vector<point> tmp;
for(int k=0; k<m.size(); k++)
if(k==0||m[k-1].g!=m[k].g)
{
tmp.push_back(m[k]);
ans=max(ans,m[k].g*(j-m[k].p+1));
}
m=tmp;
}
printf("%lld\n",ans);
}
return 0;
}
UVA 1642(p340)----Magical GCD
最新推荐文章于 2023-12-04 08:53:01 发布