枚舉右端點,往前查找左端點....
右端點一定的話,最多只有log個不同的gcd值,
用一個數組記錄不同的GCD的值,對每個相同的GCD值記錄一下最靠左的位置...
因爲GCD值不是很多所以 移動右端點時暴力統計即可..
對與樣例:
30 60 20 20 20
從第1個數座右端點開始枚舉 // (gcd,位置)
(30,1)
枚舉以第2個數做爲右端點
(30,1) (60,2)
第3個數
(10,1) (20,2)
....
後面幾個數都是一樣的...
第5個數
(10,1) (20,2)
這時 20*(5-2+1) = 80 最大
点击打开链接
1642 Magical GCDThe Magical GCD of a nonempty sequence of positive integers is defined as the product of its lengthand the greatest common divisor of all its elements.Given a sequence (a1, . . . , an), find the largest possible Magical GCD of its connected subsequence.InputThe first line of input contains the number of test cases T. The descriptions of the test cases follow:The description of each test case starts with a line containing a single integer n, 1 ≤ n ≤ 100000.The next line contains the sequence a1, a2, . . . , an, 1 ≤ ai ≤ 1012.OutputFor each test case output one line containing a single integer: the largest Magical GCD of a connectedsubsequence of the input sequence.Sample Input1530 60 20 20 20Sample Output80
/* ***********************************************
Author :CKboss
Created Time :2015年02月04日 星期三 13时12分27秒
File Name :UVA1642.cpp
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include