//UVA1642MagicalGCD
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;
typedef long long LL;
LL Gcd(LL a, LL b) {
return b == 0 ? a : Gcd(b, a % b);
}
struct Item {
LL g;
int p;
Item(LL g = 0, int p = 0) : g(g), p(p) {}
bool operator < (const Item& rhs) const {
return g < rhs.g || (g == rhs.g && p < rhs.p);
}
};
LL num[maxn];
int main() {
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%lld", &num[i]);
vector<Item> items;
LL ans = 0;
for(int i = 0; i < n; i++) {
items.push_back(Item(0, i));
for(int j = 0; j < items.size(); j++) {
items[j].g = Gcd(items[j].g, num[i]);//更新当前的各个子串的gcd
}
sort(items.begin(), items.end());
vector<Item> newitem;//筛选当前序列中剩余的部分
for(int j = 0; j < items.size(); j++) {
if(j == 0 || items[j].g != items[j - 1].g) newitem.push_back(items[j]);
ans = max(ans, items[j].g * (i - items[j].p + 1));
}
items = newitem;
}
printf("%lld\n", ans);
}
return 0;
}
/*
1
5
30 60 20 20 20
*/
UVA1642MagicalGCD
最新推荐文章于 2020-07-30 09:54:55 发布