Compute the greatest common divisor (GCD) of all n positive integers in the array. The GCD of a list is the largest positive integer that divides every element.
Line 1: an integer n.
Line 2: n space-separated positive integers.
One line: the GCD of all elements.
Example 1
Input
3 12 18 24
Expected
6
Explanation
The largest number dividing 12, 18 and 24 is 6.
Example 2
Input
2 7 13
Expected
1
Explanation
7 and 13 are coprime, so their GCD is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →