Problems > GCD of Everything

GCD of Everything

Difficulty: 1100 3000 ms 128 MB

math number-theory

Print the greatest common divisor of all N values.

Input: the first line has N; the second line has N positive integers.

Output: gcd(a1, ..., aN).

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ ai ≤ 109

Sample Tests

Input 1
3
12 18 24
Output 1
6
Input 2
2
7 13
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.