Problem:


Score : 300 points

Problem Statement

There are N monsters, numbered 1, 2, ..., N.

Initially, the health of Monster i is A_i.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

A random alive monster attacks another random alive monster.

As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.

Find the minimum possible final health of the last monster alive.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible final health of the last monster alive.

Sample Input 1

4
2 10 8 40

Sample Output 1

2

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
A = list(sorted(list(set(map(int, input().split())))))
while True:
    n = len(A)
    if n == 1 or A[0] == 1:
        break
    B = {A[0]}
    for j in range(1, n):
        m = A[j] % A[0]
        if m != 0:
            B.add(m)
    A = list(sorted(list(B)))
print(A[0])

Submission status: Accepted

Solution code:
import sys
import copy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = sorted(in_nl())

    while True:
        B = []
        B.append(A[0])
        for i in range(1, len(A)):
            x = A[i] % A[0]
            if x:
                B.append(x)

        if len(B) == 1:
            break
        else:
            B.sort()
            A = copy.copy(B)

    print(B[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

N = int(input())
A = list(map(int,input().split()))

ans = 0
for i in range(0,N,1):
    ans = gcd(ans,A[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
for i in range(n - 1):
  a, b = min(lst[i], lst[i + 1]), max(lst[i], lst[i + 1]) # a < b
  while a != 0:
    a, b = b % a, a
  lst[i + 1] = b
print(lst[n - 1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = min(a)
while True:
    for i in range(n):
        if a[i] % x == 0:
            a[i] = x
        else:
            a[i] = a[i] % x
    if x == min(a):
        print(x)
        break
    else:
        x = min(a)

Submission status: Accepted

Solution code:
import fractions

N=int(input())
A=list(map(int, input().split()))
gcdans=A[0]
for i in range(1,N):
	gcdans=fractions.gcd(gcdans,A[i])

print(gcdans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

i = 0
while i < n-1:
    x = a[i+1] % a[i]
    a[i+1] = a[i]
    a[i] = x
    if a[i] == 0:
        i += 1
print(a[i])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()

i = 0
while i < n-1:
    x = a[i+1] % a[i]
    a[i+1] = a[i]
    a[i] = x
    if a[i] == 0:
        i += 1
print(a[i])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()

i = 0
while True:
    x = a[i+1] % a[i]
    if x < a[i]:
        a[i+1] = a[i]
        a[i] = x
        if a[i] == 0:
            i += 1
            if i == n-1:
                break
    else:
        break
print(a[i])

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
A.sort()

ans=A[0]
count=[0]*N
i=0
while i<N:
    count[i]=A[i]%ans
    i+=1

for c in count:
    if c>0:
        ans=min(ans,c)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a<b:
        a,b = b,a
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b
n = int(input())
a = list(map(int,input().split()))
ans = gcd(a[0],a[1])
for i in range(2,n):
    ans = gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

while True:
    A_org = A[0:]
    min_A = max(A)
    min_index = A.index(min_A)
    for i in range(N):
        if A[i] < min_A and A[i] >= 1:
            min_A = A[i]
            min_index = i
    for i in range(N):
        if i == min_index:
            pass
        else:
            A[i] %= min_A
    if A == A_org:
        break

print(max(A))

Submission status: Accepted

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(n - 1):
    ans = math.gcd(ans, a[i + 1])
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
a_li = list(map(int,input().split()))
for i in range(n-1):
    a_li[i+1] = math.gcd(a_li[i],a_li[i+1])
print(a_li[i+1])

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

n, *a = map(int, read().split())

res = gcd(a[0],a[1])
for i in range(2,n):
    res = gcd(res, a[i])

print(res)

Submission status: Accepted

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
ans = a[0]
for i in range(1,N):
  ans = math.gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    mon1 = [a for a in A]
    mon2 = [a for a in A]

    for i in range(10**9):
        mon1 = sorted(mon2)
        mon2 = list()

        for j in range(1, len(mon1)):
            m_ = mon1[j] % mon1[0]
            if m_ != 0:
                mon2.append(m_)

        mon2.append(mon1[0])

        if len(mon2) == 1:
            break

    print(mon2[0])
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
while len(a)>1:
  c=min(a)
  b.append(c)
  for m in a:
    d= m % c
    if d>0:
      b.append(d)
  a=b[:]
  b.clear()
print(a[0])

Submission status: Accepted

Solution code:
from fractions import gcd

N = int(input())
As = list(map(int, input().split()))

rlt = As[0]

for a in As[1:]:
  rlt = gcd(a,rlt)
  
print(rlt)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

while(len(np.nonzero(A)[0]) != 1):
    devisor = np.min(A[np.nonzero(A)])
    devisor_i = np.where(A==devisor)[0][0]
    A = np.array([A[devisor_i], *(A%devisor)[:devisor_i], *(A%devisor)[devisor_i+1:]])
    
print(*A[np.nonzero(A)])

Submission status: Accepted

Solution code:
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
# print(a)
tmp = gcd(0, a[0])
for i in range(1, n):
    tmp = gcd(tmp, a[i])
print(tmp)

Submission status: Accepted

Solution code:
from fractions import gcd

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    A = list(mi())
    ans = A[0]
    for i in range(N-1):
        ans = gcd(ans, A[i+1])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]

for e in A:
    ans = gcd(e,ans)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
print(reduce(gcd,a))

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for e in A:
    ans = gcd(e,ans)
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
g = 0
for i in range(n):
    g = gcd(g,A[i])
print(g)

Submission status: Accepted

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n=I()
lis=LI()
p=lis[0]
for i in range(n-1):
    p=gcd(p,lis[i+1])
print(p)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from math import gcd

N = int(input())
A = list(map(int, input().split()))
G = 0

for Ai in A:
    G = gcd(G, Ai)

print(G)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd(*a))

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))

while len(A) > 1:
    A = sorted([i%A[0] for i in A if i%A[0]!=0] + [A[0]])
print(A[0])

Submission status: Accepted

Solution code:
import math
def computeGCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
n=int(input())
a=list(map(int,input().split()))
ans=computeGCD(a[0],a[1])
for i in range(2,n):
  ans=computeGCD(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
x = A[0]
for i in range(1,N):
    x = gcd(x,A[i])
print(x)

Submission status: Accepted

Solution code:
from math import gcd

N = int(input())
A = list(map(int,input().split()))

g = A[0]

for i in A:
    g = gcd(g,i)

print(g)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))

#import fractions
import math
from functools import reduce

def gcd(*numbers):
    #return reduce(fractions.gcd, numbers)
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    #return reduce(fractions.gcd, numbers)
    return reduce(math.gcd, numbers)

print(gcd_list(A))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
from math import gcd
for i in range(N-1):
    a = A[i]
    b = A[i+1]
    a, b = 0, gcd(a,b)
    A[i] = a
    A[i+1] = b
print(A[N-1])

Submission status: Accepted

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))

gcd=fractions.gcd(a[0],a[1])

for i in range(2,n):
    gcd=fractions.gcd(a[i],gcd)

print(gcd)

Submission status: Accepted

Solution code:
from fractions import gcd


def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = gcd(As[0], As[1])
    for i in range(2, n):
        ans = gcd(ans, As[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 解説確認後

import fractions #val 3.4

N = int(input())

a = list(map(int,input().split()))

gcd = fractions.gcd(a[0],a[1])

for i in range(2,N):
    gcd = fractions.gcd(a[i],gcd)
print(gcd)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b==0:    return a
    return gcd(b, a%b)



n=int(input())
A=list(map(int, input().split()))

ans=gcd(A[0], A[1])

for i in range(2, n):
    ans=gcd(ans, A[i])

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
print(reduce(gcd, a))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
def gcd_list(numbers):
    return reduce(gcd, numbers)
print(gcd_list(a))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from fractions import gcd

def solve():
    N = II()
    A = LI()

    ans = A[0]
    for a in A:
        ans = gcd(ans, a)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for ai in a[1:]:
    ans = gcd(ans, ai)
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
 
N = int(input())
A = list(map(int,input().split()))
ans = gcd_list(A)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
x=a[0]
for i in a:
  x=gcd(x,i)
print(x)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))

def gcd(x,y):
    if y==0: return x
    return gcd(y,x%y)
ans = A[0]
for a in A:
    ans = gcd(ans,a)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = set(map(int,input().split()))
def helper(A):
    v = min(A)
    ans = set()
    for a in A:
        if a%v!=0:
            ans.add(a%v)
    ans.add(v)
    return ans

while len(A)>1:
    A = helper(A)
print(min(A))

Submission status: Accepted

Solution code:
import fractions

n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)

last = a[0]

for i in range(1, n):
    last = fractions.gcd(last, a[i])

print(last)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import functools
import fractions
n, *a = map(int, open(0).read().split())
gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Submission status: Accepted

Solution code:
def gcd_(a, b):
    if a < b:  a, b = b, a
    if b == 0:  return a
    return gcd_(b, a % b)

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

N = int(input())
print(gcd(list(map(int,input().split()))))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

l = a[:]
while len(l) > 1:
    midx = l.index(min(l))
    r = []
    for i in range(len(l)):
        if i != midx:
            l[i] = l[i] % l[midx]
        if l[i] != 0:
            r.append(l[i])
    l = r[:]
print(l[0])

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
A.sort()
T = [A[0]]
for i in range(1,len(A)):
  if A[i]//A[0] != 0:
    T.append(A[i])
  else:
    pass

ans = A[0]
for i in range(len(T)):
  ans = gcd(ans,T[i])
print(ans)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import fractions
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=fractions.gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))

def gcd(x,y):
    if y==0:
        return x
    return gcd(y,x%y)

ans=a[0]
for i in a:
    ans=gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for i in a:
    ans = gcd(ans, i)

print(ans)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
    ans = fractions.gcd(ans,A[i])
print(ans)

Submission status: Accepted

Solution code:
#! -*- coding: utf -*-

import fractions

n = int(input())
monsters = list(map(int, input().split()))

for i in range(n-1):
    monsters[i + 1] = fractions.gcd(monsters[i], monsters[i + 1])

print(monsters[-1])

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]
g = a[0]
for i in a[1:]:
    g = gcd(g, i)
    if g == 1:
        break
print(g)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.append(0)
a = sorted(a)

while len(a) > 2:
    for i in range(2,n):
        a[i] %= a[1]
        
    a = sorted(set(a))
    n = len(a)
    
print(a[1])

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(set([int(x) for x in input().split()]))

while len(a)!=1:
    if a[0]==0:
        a=a[1:]
    for i in range(1,len(a)):
        a[i]%=a[0]
    a=sorted(set(a))

print(a[0])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  if not l:
    break
  l.append(m)
  m = min(l)
  stack = set(l)

print(m)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
lis = list(map(int, input().split()))

tmp = gcd(lis[0], lis[1])

for i in range(1, n-1):
    tmp = gcd(tmp,lis[i+1])
    
print(tmp)

Submission status: Accepted

Solution code:
def gcd(_a, _b):
	if _a%_b==0:return _b
	else:return gcd(_b, _a%_b)

n=int(input())
a=sorted(map(int,input().split()))
INF=2*10**9
ans=INF
for i in range(len(a)-1):
	tmp=gcd(a[i],a[i+1])
	if tmp!=0 and tmp<ans:
		ans=tmp
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int,input().split()))
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
#リスト l の最大公約数
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
print(gcdlist(ls))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import fractions
def gcdlist(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[i])
    return ans
print(gcdlist(a))

Submission status: Accepted

Solution code:
from fractions import gcd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = a[0]
    for aa in a:
        ans = gcd(ans, aa)
        
    print(ans)
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = min(a)
    next_m = m
    count = 0
    while count != n:
        m = next_m
        count = 0
        pre = a[0]
        for i in range(n):
            if a[i] == pre:
                count += 1
            a[i] %= m
            if a[i] != 0:
                next_m = min(next_m, a[i])
            else:
                a[i] = m
            pre = a[i]
    print(m)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(a, b):
    mod = 1
    while mod != 0:
        mod = b%a
        b = a
        a = mod
    return b

N = int(input())
A = list(map(int, input().split()))

minA = min(A)
B = [a%minA for a in A]
print(solve(minA, max(B)))

Submission status: Accepted

Solution code:
def solve(a, b):
    mod = b%a
    if mod == 0:
        return a
    else:
        return solve(mod, a)

N = int(input())
A = list(map(int, input().split()))

minA = min(A)
B = [a%minA for a in A]
print(solve(minA, max(B)))

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))

g=a[0]
for i in a[1:]:
    g = gcd(g,i)

print(g)

Submission status: Accepted

Solution code:
# 最大公約数
def gcd(a,b):
    while b != 0:
        a,b = b, a%b
    return a


n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in a:
    ans = gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
li = list(map(int,input().split()))
gcd1 = 0
gcd1 = fractions.gcd(li[0],li[1])
for i in range(2,n):
    gcd1 = fractions.gcd(gcd1,li[i])
print(gcd1)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int,input().split()))
 
print(gcd(*a))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

#最大公約数
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

gcd_calc = A[0]
for a in A[1:]:
    gcd_calc = gcd(gcd_calc, a)

print(gcd_calc)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(i) for i in input().split()])

def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])

print(ans)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for x in a:
  ans = fractions.gcd(ans, x)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for i in a:
    ans = gcd(ans, i)
print(ans)

Submission status: Accepted

Solution code:
import fractions

N = int(input())
A = list(map(int,input().split()))

ans = A[0]

for i in range(N):
  ans = fractions.gcd(A[i], ans)
  
print(ans)

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x%y==0: return y
    else: return gcd(y,x%y)
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = a[0]
for i in range(1,n):
    ans = min(ans,gcd(ans,a[i]))
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n=int(input())
a=list(map(int,input().split()))

p=gcd_list(a)

print(p)

Submission status: Accepted

Solution code:
import fractions

N = int(input())
A = list(input().split())
monster = list(sorted([int(A[i]) for i in range(N)]))
ans = float('inf')
MIN = monster[0]

for i in range(N):
    tmp = monster[i]
    ans = min(ans, int(fractions.gcd(tmp, MIN)))

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def gdc(p, q):
    if q == 0:
        return p
    return gdc(q, p%q)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 1:
        print(A[0])
        return
    res = A[0]
    for i in range(1,N):
        res = gdc(res, A[i])
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
def gcd(x,y):
    if(x<y):
        x,y=y,x
    if(y==0):
        return x
    return gcd(y,x%y)

n=l()[0]
A=l()
ans=A[0]
for i in range(1,n):
    ans=gcd(ans,A[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a:
  ans=fractions.gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import fractions
n = int(input())
a = list(map(int, input().split()))


value = a[0]
for i in range(1, n):
    value = fractions.gcd(value, a[i])
print(value)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))

    while True:
        A.sort()
        mod_max = 0
        for i in range(len(A)-1, 0, -1):
            tmp = A[i] % A[0]
            if tmp == 0:
                A.pop(i)
            else:
                A[i] = tmp
            if mod_max < tmp:
                mod_max = tmp
        if mod_max == 0:
            print(A[0])
            exit()
        elif mod_max == 1:
            print(1)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
l=list(map(int,input().split()))
s=l[0]
for a in l[1:]:
    s=gcd(s,a)
print(s)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


input()
print(reduce(gcd, map(int, input().split())))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


input()
A = map(int, input().split())
print(reduce(gcd, A))

Submission status: Accepted

Solution code:
from fractions import gcd


input()
A = map(int, input().split())
ans = next(A)
for a in A:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

N=int(input())
a=list(map(int, input().split()))
print(gcd_list(a))

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))

def gcd(v1, v2):
    if v2 == 0:
        return v1
    return gcd(v2, v1%v2)

tmp = A_list[0]
for a in A_list:
    tmp = gcd(tmp, a)

print(tmp)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
aa = tuple(map(int, input().split()))

a = aa[0]
for b in aa[1:]:
    a = gcd(a, b)
print(a)

Submission status: Accepted

Solution code:
#A1, A2, ..., AN の最大公約数を g とします。すると、以下で示すように g が答えになります。
#入力例 1 において、なぜどのように攻撃を行っても体力 1 にならないのでしょうか。これは、どのモンス
#ターも初期体力が偶数なので、攻撃して体力が変化しても偶数にしか変化しないためです。これを一般化す
#ると、体力 a のモンスターが体力 b (b > a) のモンスターに攻撃したときに攻撃されたモンスターの体力は
#b − a となりますが、a も b も x の倍数であるなら b − a も x の倍数です。したがって、常に x として g を
#取れるので、生きているモンスターの体力は必ず g の倍数となり、g 未満になることはありません。
#逆に、次のように最後に生き残ったモンスターの体力を g にすることができます。体力 a のモンスターと
#体力 b のモンスターがお互いの体力が等しくなるまで体力の低いほうが高い方を攻撃し続けるとユークリッ
#ドの互除法と同じ遷移になるため最終的な体力はお互いに a と b の最大公約数になります。これを 1 番目の
#モンスターと 2 番目のモンスター, 2 番目のモンスターと 3 番目のモンスター, ... と順に行うと、最終的に N
#番目のモンスターの体力が A1, A2, ..., AN の最大公約数 g になります。最後に N 番目のモンスターが他の
#モンスターを攻撃し続ければ、最後に生き残ったモンスター (N 番目のモンスター) の体力が g になります。
#実装は、ユークリッドの互除法により A1, A2, ..., AN の最大公約数を求めて出力すればよく、これは
#O(N + logA1) で動作します。

import fractions
n = int(input())
a = list(map(int,input().split()))

g =a[0]

for i in range(n-1):
  g = fractions.gcd(g,a[i+1])
  
print(g)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))

g =a[0]

for i in range(n-1):
  g = fractions.gcd(g,a[i+1])
  
print(g)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
nums = [int(i) for i in input().split()]

print(gcd_list(nums))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))

g= A[0]
import fractions
for i in range(1,n):
    g = fractions.gcd(g, A[i])
print(g)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
import fractions
ans = a[0]
for i in range(1, n):
    ans = fractions.gcd(ans, a[i])
print(ans)

Submission status: Accepted

Solution code:
import itertools
import fractions
n=int(input())
a=list(map(int,input().split()))
a.sort()
mina=a[0]
ans = 10**18
for i in range(n):
	ans = min(ans, fractions.gcd(a[i], mina))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))

g= A[0]
import fractions
for i in range(1,n):
    g = fractions.gcd(g, A[i])
print(g)

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)