//看看会不会爆int! #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define pb push_back #define mkp make_pair #define fi first #define se second #define FOR(i, l, r) for(int i = l; i <= r; i++) #define ROF(i, r, l) for(int i = r; i >= l; i--) #define all(a) a.begin(), a.end() int n, T; ll maxans; int a[300100], fa[300100], b[300100], c[300100]; ll size[300100]; bool cmp(const int x, const int y) { return b[x] > b[y]; } inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } inline void merge(int x, int y){ int xx = find(x), yy = find(y); fa[xx] = yy, size[yy] += size[xx]; } void read(int &rt){ rt=0;char ch=getchar(); while(ch>'9'||ch<'0')ch=getchar(); while(ch<='9'&&ch>='0')rt=rt*10+ch-'0',ch=getchar(); } int main(){ read(T); while(T--){ read(n); maxans = 0; for(int i = 1; i <= n; i++) read(a[i]); for(int k = 1; k <= n; k++){ ll ans = 0; int m = 0; for(int i = k; i <= n; i += k) b[m] = a[i], c[m] = m, fa[m] = -1, m++; sort(c, c + m, cmp); for(int i = 0; i < m; i++){ int j = c[i]; fa[j] = j; size[j] = b[j]; if(j && fa[j - 1] != -1) merge(j, j - 1); if(j < m - 1 && fa[j + 1] != -1) merge(j, j + 1); ans = max(ans, (ll)b[j] * size[find(j)]); } ans *= int(sqrt(k + 0.1)); maxans = max(maxans, ans); } cout << maxans << endl; } return 0; } /* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */