#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
map<ll,ll>
mmp;
int t,n;
ll x;
ll gcd(ll a,ll b)
{
return b==
0?a:gcd(b,a%
b);
}
int main()
{
scanf("%d",&
t);
while(t--
)
{
ll ans=
0;
mmp.clear();
scanf("%d",&
n);
for(
int i=
1;i<=n;i++
)
{
scanf("%lld",&
x);
if(!mmp.count(x)) mmp[x]=i;
//存自己,作为map内一项
for(map<ll,ll>::iterator it=mmp.begin();it!=
mmp.end();)
{
ll temp=gcd(x,it->
first);
ans=max(ans,temp*(i-it->second+
1));
if(!mmp.count(temp)) mmp[temp]=it->
second;
else mmp[temp]=min(mmp[temp],it->second);
//使最大公因数的i最小,使ans尽量大
if(temp< it->
first)
mmp.erase(it++);
//如果他的最大公因数比它小,那么它就可以被代替
else it++
;
}
}
printf("%lld\n",ans);
}
return 0;
}
转载于:https://www.cnblogs.com/Wangwanxiang/p/8433167.html
相关资源:数据结构—成绩单生成器