Sereja and Array and Subtracting
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Sereja has an array A of N positive integers : A, A, A, ... , A[N].
In a single operation on the array, he performs the following two steps :
- Pick two indices i, j s.t. A[i] > A[j]
- A[i] -= A[j]
Sereja can apply these operations any number of times (possibly zero), such that the sum of resulting elements of the array is as small as possible.
Help Sereja find this minimum sum.
First line of input contains an integer T - the number of test cases. T test cases follow.
First line of each test case contains the integer N. The next line contains N integers — A, A, A, ... , A[N].
OutputFor each test case, output a single line with the answer.
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 105
- 1 ≤ A[i] ≤ 109
Input: 2 1 1 3 2 4 6 Output: 1 6
Example case 2. In this case, one possible way in which Sereja can perform the operations could be as follows.
- Pick i = 2, j = 1. A -= A. Now the resulting array would be [2, 2, 6].
- Pick i = 3, j = 2. A -= A. Now the resulting array would be [2, 2, 4].
- Pick i = 3, j = 2. A -= A. Now the resulting array would be [2, 2, 2].
|Tags||cook64, easy, gcd, mathematics, number-theory, sereja|
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, 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, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.