#K43567. Largest Common Divisor in Sequences
Largest Common Divisor in Sequences
Largest Common Divisor in Sequences
Given several sequences of integers, for each sequence, find the largest divisor d such that every number in the sequence is divisible by d. In other words, compute the greatest common divisor (GCD) for the sequence.
For a sequence \(a_1, a_2, \ldots, a_n\), the answer is given by \[ d = \gcd(a_1, a_2, \ldots, a_n)\]
You need to process multiple test cases. For each test case, you'll be given the number of elements in the sequence, followed by the sequence itself. Output the GCD for each test case on a separate line.
inputFormat
The input is read from standard input (stdin). The first line contains an integer T specifying the number of test cases. Each test case consists of two lines:
- The first line contains an integer n which is the number of elements in the sequence.
- The second line contains n space-separated integers.
outputFormat
For each test case, print the greatest common divisor (GCD) of the sequence on a new line to standard output (stdout).
## sample3
3
2 4 6
4
5 10 15 20
5
6 9 12 15 18
2
5
3
</p>