Sum and GCD

All submissions for this problem are available.
### Read problem statements in [Hindi](http://www.codechef.com/download/translated/JUNE19/hindi/SUMAGCD.pdf), [Bengali](http://www.codechef.com/download/translated/JUNE19/bengali/SUMAGCD.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/JUNE19/mandarin/SUMAGCD.pdf), [Russian](http://www.codechef.com/download/translated/JUNE19/russian/SUMAGCD.pdf), and [Vietnamese](http://www.codechef.com/download/translated/JUNE19/vietnamese/SUMAGCD.pdf) as well. Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two nonempty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Help him find this maximum value. Note: The greatest common divisor (GCD) of a sequence of positive integers is the largest positive integer that divides each element of this sequence. For example, the GCD of the sequence $(8, 12)$ is $4$. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains a single integer $N$.  The second line contains $N$ spaceseparated integers $A_1, A_2, \ldots, A_N$. ### Output For each test case, print a single line containing one integer — the maximum value of $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$. ### Constraints  $1 \le T \le 10$  $2 \le N \le 10^5$  $1 \le A_i \le 10^9$ for each valid $i$ ### Subtasks **Subtask #1 (20 points):** $2 \le N \le 20$ **Subtask #2 (80 points):** original constraints ### Example Input ``` 1 4 4 4 7 6 ``` ### Example Output ``` 9 ``` ### Explanation **Example case 1:** For example, the sequence $A$ can be divided into subsequences $B = (4, 4, 6)$ and $C = (7)$.Author:  roman_derkach 
Editorial  https://discuss.codechef.com/problems/SUMAGCD 
Tags  june19, junechallenge, roman_derkach 
Date Added:  30042019 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions