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())
hps = sorted(list(map(int, input().split())))

while len(hps) > 1:
    for i in range(1, len(hps)):
        hps[i] = hps[i] % hps[0]
    hps = sorted(set(hps))
    if 0 in hps:
        hps.remove(0)
print(hps[0])

Submission status: Accepted

Solution code:
import fractions

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

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

print(a[N-1])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
while len(a)>1:
    for i in range(len(a)):
        if not i==0:
            a[i] %= a[0]
    a = sorted(list(set(a)))
    if a[0]==0:
        a.pop(0)
print(a[0])

Submission status: Accepted

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

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

Submission status: Accepted

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

while len(a) > 1:
    min_ = a[-1]
    new = []
    for i in a:
        if i % min_ :
            new.append(i%min_)
    new.append(min_)
    new.sort(reverse=True)
    a = new
print(a[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


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

@mt
def slv(N, A):
    ans = reduce(gcd, A)
    return ans


def main():
    N = read_int()
    # N, M = read_int_n()
    A = read_int_n()
    # A = [read_int_n() for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

N = I()
A = IL()

ans = gcd(A[0],A[1])
for i in A:
  if i%ans != 0:
    ans = gcd(ans,i)
  if ans == 1:
    break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import reduce, lru_cache
from fractions import gcd

N = int(input())
A = [int(x) for x in input().split()]

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
def fgcd(a,b):
    while b:
        a,b = b,a%b
    return a

N = int(input())
aA = [int(_) for _ in input().split()]
b = aA[0]
for a in aA[1:]:
    b = fgcd(a,b)
    if b == 1:
        print(1)
        exit()
print(b)

Submission status: Accepted

Solution code:
N = int(input())
aA=[int(_) for _ in input().split()]
iMin = min(aA)
iMax = max(aA)

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

if iMin  == 1:
    print(1)
else:
    iDm = [ _ % iMin for _ in aA]
    if max(iDm) == 0:
        print(iMin)
    else:
        b = aA[0]
        for _ in aA[1:]:
            b = fgcd(_,b)
            if b == 1:
                print(1)
                exit()
        print(b)

Submission status: Accepted

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


def dcg(a, b):
    while not (a == 0 or b == 0):
        if a > b:
            a %= b
        else:
            b %= a
    return a + b


for i in range(N-1):
    A[i+1] = dcg(A[i], A[i+1])
print(A[-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

while len(A_list) > 1:
    min_A = min(A_list)
    A_list = [min_A] + [A % min_A for A in A_list if A % min_A != 0]

print("{}".format(A_list[0]))

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=gcd(a[0],a[1])
if n>2:
  for i in range(2,n):
    ans=gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import collections

N = int(sys.stdin.readline())

monster = [int(a) for a in sys.stdin.readline().strip().split()]
monster.sort()

while len(monster)>1:
    for i in range(1,len(monster)):
        monster[i] %= monster[0]
    monster.sort()
    while monster[0]==0:
        monster.pop(0)
    


print(monster[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce


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


N = int(input())
A = list(map(int, input().split()))
print(reduce(lambda a, b: gcd(a, b), A))

Submission status: Accepted

Solution code:
# import math
from functools import reduce
input()
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def gcds(*numbers):
    return reduce(gcd, numbers)
print(gcds(*[int(i) for i in input().split()]))

Submission status: Accepted

Solution code:
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    M = [mini] + [x%mini for x in M[1:] if x % mini != 0]
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(M[0])

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd


n = int(input())
array = sorted([int(x) for x in input().split()])

tmp = array[0]
for num in array[1:]:
    tmp = gcd(tmp, num)
print(tmp)

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()))
answer = gcd_list(A)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(x , y):
    if x < y:
        x , y = y , x
    if y == 0:
        return x
    r = x % y
    return gcd(y , r)

N = int(input())
L = list(map(int,input().split()))
ans = L[0]
for i in range(len(L)):
    ans = gcd( ans ,L[i] )
print(ans)

Submission status: Accepted

Solution code:
import fractions as p,functools as f;input();print(f.reduce(p.gcd,map(int,input().split())))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    b = min(A)
    for a in A:
        while True:
            if a % b == 0:
                break
            tb = b
            b = a % b
            a = tb
    print(b)


main()

Submission status: Accepted

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

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

G = A[0]
for i in range(len(A)-1):
  G = gcd(G, A[i+1])
  
print(G)

Submission status: Accepted

Solution code:
import functools as f,fractions as p;_,*a=map(int,open(0).read().split());print(f.reduce(p.gcd,a))

Submission status: Accepted

Solution code:
import fractions as p,functools as f
_,a=input(),list(map(int,input().split()))
print(f.reduce(p.gcd,a))

Submission status: Accepted

Solution code:
import fractions as p,functools as f
input()
print(f.reduce(p.gcd,list(map(int,input().split()))))

Submission status: Accepted

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

Submission status: Accepted

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

#
# Tips:
# - Use pbcopy command to copy this file to clipboard.
#

################################################################################

import math
from math import *
from math import factorial as fact
import itertools
from functools import reduce
#import numpy
#import scipy, scipy.special

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

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

def gcd_multi(l):
    return reduce(lambda x, y: gcd(x, y), l)

def input_ints(inp = input, sep = ' ', conv = lambda x: int(x)):
    return [conv(x) for x in inp().split(sep = sep)]

################################################################################

N = input_ints()
A = input_ints()

print(gcd_multi(A))

Submission status: Accepted

Solution code:
import functools as f,fractions as p
_,*a=map(int,open(0).read().split())
print(f.reduce(p.gcd,a))

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
    if a>b:
        a,b=b,a
    while b:
        a,b=b,a%b
    return a
c=a[0]
for i in range(N-1):
    c=gcd(c,a[i+1])
print(c)

Submission status: Accepted

Solution code:
import fractions as p,functools as f;input();print(f.reduce(p.gcd,list(map(int,input().split()))))

Submission status: Accepted

Solution code:
def gcd(a,b):
    r = a%b
    #print(a,b,r)
    if(r==0): return b
    return gcd(b,r)
n = int(input()) 
#n=4
hps = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
    ##2 4 5 -> 1
    ## minと全ての要素のgcd
hps = sorted(hps)
for i in range(1,n):
    hps[0] = gcd(hps[i], hps[0])
#print(hps)
for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])
    break

Submission status: Accepted

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

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x
ans = gcd(a[0],a[1])
for i in a[2:]:
	ans = gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import fractions as p, functools as f;input();print(f.reduce(p.gcd, list(map(int, input().split()))))

Submission status: Accepted

Solution code:
import functools as f,fractions as p
_=input()
print(f.reduce(p.gcd,list(map(int,input().split()))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions, functools;input();print(functools.reduce(fractions.gcd, list(map(int, input().split()))))

Submission status: Accepted

Solution code:

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

assert (gcd(10, 3) == 1)

def solve(N, As):
    k = min(As)
    for a in As:
        k = gcd(k, a)
    return k

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

Solution code:
from functools import reduce

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


if __name__ == '__main__':
    n = int(input())
    a = [int(s) for s in input().split()]
    print(reduce(gcd, a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
_=input()
print(reduce(gcd,map(int,raw_input().split())))

Submission status: Accepted

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

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
n = int(input())
a = [i for i in map(int, input().split())]
ans = gcd(a[0], a[1])
if 2 < n:
    for i in a[2:]:
        ans = gcd(ans, i)
print(ans)

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 sys import stdin
from functools import reduce
import fractions
#input = stdin.readline
N = int(input())
A = list(set(map(int,input().split())))
answer = reduce(fractions.gcd, A)
print(answer)

Submission status: Accepted

Solution code:

n=int(input())
a=[int(i) for i in input().split()]
c=a[0]
def gcd(x,y):
    while y:
        x,y=y,x%y
    return x

for i in a:
    c=gcd(c,i)
print(c)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return x
G = gcd(L[0],L[1])
for i in range(1,N-1):
  if G >= gcd(L[i],L[i+1]):
    G = gcd(L[i],L[i+1])
print(G)

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
for s in range(len(a)-1):
  if s==0:x=a[s]
  x=gcd(x,a[s+1])
print(x)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a_list = list(map(int, input().split()))
num = a_list[0]

for i in range(n):
    num = fractions.gcd(num, a_list[i])
print(num)

Submission status: Accepted

Solution code:
#ABC118C-MonstersBattleRoyale.py

from sys import stdin
from functools import reduce
import fractions

input = stdin.readline

N = int(input())

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

answer = reduce(fractions.gcd, A)
print(answer)

Submission status: Accepted

Solution code:
def gcd(m: int, n: int):

    if n == 0:
        return m

    return gcd(n, m % n)


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

A.sort(reverse=True)

num = A[0]

for i in range(1, N):

    if A[i] > num:
        big = A[i]
        small = num
    else:
        big = num
        small = A[i]

    num = gcd(big, small)

print(num)

Submission status: Accepted

Solution code:
input()
A = list(map(int, input().split(" ")))
A.sort()
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
rtn = 0
for i in range(0,len(A)-1):
    A[i+1] = gcd(A[i], A[i+1])
print(A[-1])

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
 
# 最大公約数を求める関数
def gcd(a,b):
    rem = a % b
    while rem != 0:
        a = b
        b = rem
        rem = a % b
    return b
 
cand = A[0]
 
for i in range(1,N):
    cand = gcd(cand, A[i])
 
    if cand == 1:
        break
 
print(cand)

Submission status: Accepted

Solution code:
#coding:utf-8
N  = int(input())
A = list(map(int,input().split()))
def c(A,B):
    for a,b in zip(A,B):
        if a != b:
            return False
    return True
while True:
    A.sort()
    prev = A[:]
    
    s = A[0]
    for i in range(N):
        if A[i] % s == 0:
            A[i] = s
        else:
            A[i] = A[i] % s
    A.sort()
    #print("A  :",A)
    #print("pre:",prev)
    if prev == A: break
#print("A  :",A)
#print("pre:",prev)
print(A[0])

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

Submission status: Accepted

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


def euclid_lcf(a, b):
    if b < a:
        a, b = b, a

    if b % a == 0:
        return a
    else:
        r = b % a
        return euclid_lcf(a, r)


com_factor = euclid_lcf(a[0], a[1])

if len(a) == 2:
    print(com_factor)
else:
    for i in range(2, len(a)):
        com_factor = euclid_lcf(com_factor, a[i])

    print(com_factor)

Submission status: Accepted

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

while True:
    mina = min(A)
    minain = A.index(mina)
    for i in range(len(A)):
        A[i] = A[i] % mina
    if A.count(0) == len(A):
        break
    else:
        A[minain] = mina
        A = list(filter(lambda s:s != 0, A))
        
print(mina)

Submission status: Accepted

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

def func_gcd(a,b):
    if b == 0:
        return a
    else:
        return func_gcd(b,a%b)

if len(a) == 1:
    print(a[0])
else:
    res = func_gcd(a[0],a[1])
    for i in range(2,n):
        res = func_gcd(res,a[i])
    print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def read():
    return int(input())

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

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

n = read()
a = reads()
ans = a[0]
for i in range(n):
    ans = gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

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

print(b)

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()))
#単純に最大公約数を算出すればよい

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

 


print(kari)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else:
    c=sorted(b)
    x=1
    while x>0:
        v=c[0]
        for i in range(len(c)):
            if i!=0:
                c[i]=c[i]%v
        while 0 in c:
            c.remove(0)
        c=sorted(list(set(c)))
        if len(c)==1:
            print(c[0])
            exit()
        if c[0]==1:
            x=0
print(1)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)

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

b = a[0]
for i in range(n - 1):
    b = gcd(a[i + 1], b)

print(b)

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
g = A[0]
for a in A:
    g = gcd(g,a)
print(g)
#copy code

Submission status: Accepted

Solution code:
#gcdか....
def fgcd(a,b):
    while b:
        a,b = b,a%b
    return a

N = int(input())
aA = sorted(set(int(_) for _ in input().split()))
b = aA[0]
for a in aA[1:]:
    b = fgcd(a,b)
print(b)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

n = int(input())
print(gcd_list([int(i) for i in input().split()]))

Submission status: Accepted

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

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 = A[0]
for i in range(1,N):
    ans = gcd(ans, A[i])
print( ans)

Submission status: Accepted

Solution code:
import copy
N = int(input())
a = list(map(int,input().split()))
b = copy.deepcopy(a)
while max(a) != min(a):
    mina = min(a)
    for i in range(N):
        if a[i] % mina == 0:
            a[i] = mina
        else:
            a[i] = a[i] % mina
print(min(a))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)

Submission status: Accepted

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

while len(x) > 1:
    i = 0
    next = []
    while i < len(x) - 1:
        next.append(gcd(x[i], x[i+1]))
        i += 2

    x = [] + next

print(x[0])

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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


def gcd_multi(*numbers):
    return reduce(gcd, numbers)


print(gcd_multi(*monsters))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = int(input())
listA=list(map(int, input().split()))
print(gcd_list(listA))

Submission status: Accepted

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

# 最大公約数を求める関数
def gcd(a,b):
    rem = a % b
    while rem != 0:
        a = b
        b = rem
        rem = a % b
    return b

cand = A[0]

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

    if cand == 1:
        break

print(cand)

Submission status: Accepted

Solution code:
N = int(input())
p = [int(x) for x in input().split(' ')]
#N = 4
#p = [5,3,8,1000]
#p = [1000,1000,1001,1000]

def check(a,b):
  while True:
    r = b % a
    if r != 0:

      #print(a,b,r)
      b = a
      a = r
    else:
      res = a
      #print('zero')
      break

  #print(res)
  return res

mval = -1
for i in range(N-1):
  a,b=p[i],p[1]
  m = check(a,b)
  if mval == -1:
    mval = m
  else:
    if m < mval:
      mval = m
      
print(mval)

Submission status: Accepted

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

# LCM
def LCM(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a
res = A_list[0]
for i in range(N):
    res = LCM(res, A_list[i])
print(res)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

print(gcd_list(A))

Submission status: Accepted

Solution code:
from fractions import gcd
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])

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

print(a)

Submission status: Accepted

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

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

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:
def gcd(x, y):
  while(y):
    x, y = y, x % y
  return x
n = int(input())
mon = list(map(int, input().split()))
g = mon[0]
for i in range(1, n):
  g = gcd(g, mon[i])
print(g)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd 

n = int(input())
a_set = set(map(int, input().split()))
max_a = max(a_set)
min_sub = max_a

for val in a_set:
    min_sub = min(gcd(max_a, val), min_sub)
    if min_sub == 1:
        print(1)
        exit()
print(min_sub)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]

    A = sorted(A)
    list.append(min(A))
    if iii > 32:
        break       
#print(list)
for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])
#print(list)
print(min(list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


# 整数(x, y)最大公約数を求める
def gcd(x, y):
    if x % y == 0:
        return y
    else:
        x, y = y, x % y
        return gcd(x, y)


n = II()
A = LI()

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, al))

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import fractions
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
 
n = int(input())
a = list(map(int, input().split()))
a = deque(sorted(a))
ans = 0
for i in a:
    ans = fractions.gcd(ans, i)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N = int(input())
A = sorted([int(i) for i in input().split()])
print(reduce(lambda a, b: gcd(a, b), A))

Submission status: Accepted

Solution code:
from fractions import gcd
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])

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

print(a)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]

    A = sorted(A)
    list.append(min(A))
    if iii > 64:
        break       
#print(list)
for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])
#print(list)
print(min(list))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
b.sort()
     
d = b[0] + 0
 
while len(b) > 1 :
    for i in range(1,len(b)) :
        b[i] = b[i] % b[0]
    if b.count(0) == len(b)-1 :
        d = b[0]
        break
    else :
        b.sort()
        for j in range(b.count(0)) :
            b.remove(0)
print(d)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])

A=np.sort(A)
s=A[0]
for i in range(max([n, s])):
    c = A[0]
    A = A % c
    A[0] = c
    z=len(A) - np.count_nonzero(A)
    A=np.sort(A)[z:]
    if len(A) == 1:
        break
print (A[0])

Submission status: Accepted

Solution code:
input()
A=set(map(int,input().split()))
R=max(A)
while 1:
 r=min(A)
 if r==R:break
 A=set(i%r for i in A)-{0}|{r};R=r
print(R)