Problem:


 問題 ２

　入力ファイルの１行目に正整数 n が書いてあり，
２行目には半角空白文字１つを区切りとして， 
n 個の正整数が書いてある．
n は 2 または 3 であり，
２行目に書かれているどの整数も値は 108 以下である． 
これら２個または３個の数の公約数をすべて求め，
小さい方から順に1行に1個ずつ出力せよ．
自明な公約数（「１」）も出力すること．

　
出力ファイルにおいては，
出力の最後行にも改行コードを入れること．

入出力例

入力例１

2
75 125

出力例１

1
5
25

入力例２

3
110 22 88

出力例２

1
2
11
22

入力例３

3
66 11 3

出力例３

1

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
2
75 125


Sample output:
1
5
25

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
gcd_set = set()

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

if n == 2 :
    a, b = map(int, input().split())
    gcd = do_gcd(max(a, b), min(a, b))

    for i in range(1, int(math.sqrt(gcd) + 1)) :
        if gcd % i == 0 :
            gcd_set.add(i)
            gcd_set.add(int(gcd / i))
else :
    a, b, c = map(int, input().split())
    _gcd = do_gcd(max(a, b), min(a, b))
    gcd = do_gcd(max(_gcd, c), min(_gcd, c))
    
    for i in range(1, int(math.sqrt(gcd) + 1)) :
        if gcd % i == 0 :
            gcd_set.add(i)
            gcd_set.add(int(gcd / i))

            
for i in gcd_set :
    print(i)

Submission status: Wrong Answer

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

    b = []
    for x in range(n): #?´???°?????????
        hoge = [i for i in range(1, a[x] + 1)]
        fuga = []
        for y in range(len(hoge)):
            if a[x] % hoge[y] == 0:
                fuga.append(hoge[y])
            else:
                pass
        b.append(fuga)

    if n == 2: #????´???°????????????
        c = list(set(b[0]) & set(b[1]))
    else:
        c = list(set(b[0]) & set(b[1]) & set(b[2]))

    for x in range(len(c)):
        print(c[x])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

n = int(input())
lis = list(map(int, input().split()))
if n == 2:
  a, b = lis[0],lis[1]
  an = gcd(a,b)
else:
  a, b ,c = lis[0],lis[1], lis[2]
  an = gcd(gcd(a,b),c)
anlis = [an]
while(True):
  for i in range(2,an+1):
    if an % i == 0:
      an //= i
      anlis.append(an)
      break
  if an == 1:
    break
anlis.sort()
ans = ""
for j in anlis:
  print(j)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n == 3:
    while a[1] % a[2] != 0:
        r = a[1] % a[2]
        a[1] = a[2]
        a[2] = r
    a[1] = a[2]
while a[0] % a[1] != 0:
    r = a[0] % a[1]
    a[0] = a[1]
    a[1] = r

if a[1] == 1:
    print(1)
else:
    y = [1]
    i = 2
    while len(y) == 1 or i <= int(a[1] / y[1] + 1):
        if a[1] % i == 0:
            y.append(i)
        i += 1
    for i in y:
        print(i)

Submission status: Wrong Answer

Solution code:
input()
n=sorted(list(map(int,input().split())))
m=n[0]
a=[]
for x in range(1,int(m**.5)+1):
    if m%x==0:a+=[x,m/x]
for c in sorted(a):
    for k in n[1:]:
        if k%c:break
    else:print(c)

Submission status: Wrong Answer

Solution code:
input()
n=sorted(list(map(int,input().split())))
m=n[0]
a=[]
for x in range(1,int(m**.5)+1):
    if m%x==0:a+=[x,m//x]
for c in sorted(a):
    for k in n[1:]:
        if k%c:break
    else:print(c)

Submission status: Wrong Answer

Solution code:
def run():
    n = int(input())
    nls = sorted([int(i) for i in input().split()])
    result = []
    for i in range(1, nls[0] + 1):
        flag = 1
        for j in nls:
            if j % i:
                flag = 0
                break
            else:
                continue
        if flag:
            result.append(i)
    print(" ".join(map(str, result)))

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
def run():
    n = int(input())
    nls = sorted([int(i) for i in input().split()])
    result = []
    for i in range(1, nls[0] + 1):
        flag = 1
        for j in nls:
            if j % i:
                flag = 0
                break
            else:
                continue
        if flag:
            result.append(i)
        for i in result:
            print(i)

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
import math

n = int(input())
gcd_set = set()

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

if n == 2 :
    a, b = map(int, input().split())
    gcd = do_gcd(max(a, b), min(a, b))

    for i in range(1, int(math.sqrt(gcd) + 1)) :
        if gcd % i == 0 :
            gcd_set.add(i)
            gcd_set.add(int(gcd / i))
else :
    a, b, c = map(int, input().split())
    _gcd = do_gcd(max(a, b), min(a, b))
    gcd = do_gcd(max(_gcd, c), min(_gcd, c))
    
    for i in range(1, int(math.sqrt(gcd) + 1)) :
        if gcd % i == 0 :
            gcd_set.add(i)
            gcd_set.add(int(gcd / i))

            
for i in sorted(gcd_set) :
    print(i)

Submission status: Accepted

Solution code:
from math import gcd
n = int(input())
if n == 2:
    a,b = [int(i) for i in input().split()]
    for i in range(1,gcd(a,b)+1):
        if a % i == 0 and b % i == 0:
            print(i)
else:
    a,b,c = [int(i) for i in input().split()]
    g = gcd(gcd(a,b),c)
    for i in range(1,g+1):
        if a % i == 0 and b % i == 0 and c % i == 0:
            print(i)

Submission status: Accepted

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


n = int(input())
integers = sorted([int(x) for x in input().split()])
min_gcd = integers[n-1]
for i in range(n):
    for j in range(i):
        a = integers[i]
        b = integers[j]
        min_gcd = min(gcd(a, b), min_gcd)


for i in range(1, min_gcd+1):
    if sum([x % i for x in integers]) == 0:
        print(i)

Submission status: Accepted

Solution code:
import math
def gcd(a,b):
    if a < b: a, b = b, a
    while a % b != 0:
        c = a / b
        a -= c * b
        a, b = b, a 
    return b
def div(a):
    ret = set()
    for i in range(1,int(math.sqrt(a))+1):
        if a % i == 0: ret.add(i); ret.add(a/i);
    return sorted(ret)
n = input()
l = map(int, raw_input().split())
if n==2: ans = div(gcd(l[0], l[1]))
else: ans = div(gcd(gcd(l[0], l[1]), l[2]))
for i in ans: print i

Submission status: Accepted

Solution code:
from fractions import gcd
from math import sqrt
def div(a):
    ret = set()
    for i in range(1,int(sqrt(a))+1):
        if a % i == 0: ret.add(i); ret.add(a/i);
    return sorted(ret)
n = input()
l = map(int, raw_input().split())
ans = div(reduce(gcd,l))
for i in ans: print i

Submission status: Accepted

Solution code:
import functools
def gcd(a,b):
    while b:a,b=b,a%b
    return a
input()
a=list(map(int,input().split()))
b=functools.reduce(gcd,a)
for i in range(b):
    if not b%(i+1):print(i+1)

Submission status: Accepted

Solution code:
n = int(input())
values = list(map(int, input().split()))
minv = min(values)+1
print(1)
i = 2
ng_value = [1]*minv
while i < minv:
    if not 0 in [1 if values[k] % i == 0 else 0 for k in range(n)]:
        print(i)
    else:
        for j in range(i, minv, i):
            ng_value[j] = 0
    b = True
    for j in range(i+1, minv):
        if ng_value[j]:
            i = j
            b = False
            break
    if b: break

Submission status: Accepted

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

    b = []
    for x in range(n): #?´???°?????????
        hoge = [i for i in range(1, a[x] + 1)]
        fuga = []
        for y in range(len(hoge)):
            if a[x] % hoge[y] == 0:
                fuga.append(hoge[y])
            else:
                pass
        b.append(fuga)

    if n == 2: #????´???°????????????
        c = sorted(list(set(b[0]) & set(b[1])))
    else:
        c = sorted(list(set(b[0]) & set(b[1]) & set(b[2])))

    for x in range(len(c)):
        print(c[x])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0583

"""
import sys
from sys import stdin
from itertools import combinations
from functools import reduce
input = stdin.readline



def solve2():
    divs = [1]
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a

    for i in range(2, a+1):
        while a%i == 0 and b%i == 0:
            divs.append(i)
            a //= i
            b //= i

    t = divs[:]
    for i in range(2, len(divs)):
        for c in combinations(divs[1:], i):
            p = reduce(lambda x, y: x*y, c)
            t.append(p)
    st = list(set(t))
    st.sort()
    return st


def solve3():
    divs = [1]
    A = [int(x) for x in input().split()]
    A.sort()
    a, b, c = A[0], A[1], A[2]

    for i in range(2, a+1):
        while a%i == 0 and b%i == 0 and c%i == 0:
            divs.append(i)
            a //= i
            b //= i
            c //= i

    t = divs[:]
    for i in range(2, len(divs)):
        for combi in combinations(divs[1:], i):
            p = reduce(lambda x, y: x*y, combi)
            t.append(p)
    st = list(set(t))
    st.sort()
    return st


def main(args):
    num = int(input())
    if num == 2:
        result = solve2()
    else:
        result = solve3()
    print('\n'.join(map(str, result)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []
a.sort()
for i in range(1, a[0] + 1):
    if list(map(lambda x: x % i, a)) == [0] * n:
        ans.append(i)
for j in ans:
    print(j)

Submission status: Accepted

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

n = int(input())
if n == 2:
    a, b = map(int, input().split())
else:
    a, b, c = map(int, input().split())
    a = gcd(a, c)
m = gcd(a, b)
for i in range(1, m+1):
    if m % i == 0:
        print(i)

Submission status: Accepted

Solution code:
import sys

def common_divisor(x):
    List = []
    for data in x:
        if(data < 1):
            List.append(0)
    for i in range(1,min(x)+1):
        stat = 1
        for data in x:
            if(data % i != 0):
                stat = 0
                break
        if(stat == 1):
            List.append(i)
    return List

List = []

for i in sys.stdin:
    List.append(i.split())

for i in range(0,len(List[1])):
    List[1][i] = int(List[1][i])

res = common_divisor(List[1])

for data in res:
    print data

Submission status: Accepted

Solution code:
def gcd(a,b):
    a,b = sorted([a,b])
    if a==1:
        return 1
    c = b%a
    if c==0:
        return a
    return gcd(c,a)

def yakusu(n):
    return [
        a
        for a
        in range(1,n+1)
        if n%a==0
    ]

def main():
    input()
    ns = [int(a) for a in input().split()]
    a = ns[0]
    b = ns[1]
    g = gcd(a,b)
    if len(ns)==3:
        g = gcd(g,ns[2])

    for a in yakusu(g):
        print(a)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = [int(v) for v in input().split(' ')]
m = max(l)
for v in range(m):
    if v == 0: continue
    if len(list(filter(lambda x: x % v == 0, l))) == n: print(v)

Submission status: Accepted

Solution code:
n = int(input())
a=list(map(int,input().split()))
for i in range(1,min(a)+1):
    flag = True
    for j in range(len(a)):
        if(a[j]%i!=0):
            flag = False
    if  flag==True:
        print(i)

Submission status: Accepted

Solution code:


if __name__ == '__main__' :
    n = int(input())
    s = [int(i) for i in input().split(" ")]
    for i in range(1,min(s)+1):
        if (sum(map(lambda x : x % i , s)) == 0): print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n == 3:
    while a[1] % a[2] != 0:
        r = a[1] % a[2]
        a[1] = a[2]
        a[2] = r
    a[1] = a[2]
while a[0] % a[1] != 0:
    r = a[0] % a[1]
    a[0] = a[1]
    a[1] = r

if a[1] == 1:
    print(1)
else:
    y = [1]
    i = 2
    while len(y) == 1 or i <= int(a[1] / y[1] + 1):
        if a[1] % i == 0:
            y.append(i)
        i += 1
    for i in y:
        print(i)
    print(a[1])

Submission status: Accepted

Solution code:
input()
n=list(map(int,input().split()))
[print(x)for x in range(1,min(n)+1)if sum(m%x for m in n)==0]

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(int,input().split()))
a,b=s[:2]
while b:a,b=b,a%b
if n-2:
 b=s[2]
 while b:a,b=b,a%b
[print(x)for x in range(1,a+1)if a%x==0]

Submission status: Accepted

Solution code:
input()
s=list(map(int,input().split()))
a,b=s[:2]
while b:a,b=b,a%b
if len(s)-2:
 b=s[2]
 while b:a,b=b,a%b
[print(x)for x in range(1,a+1)if a%x==0]

Submission status: Accepted

Solution code:
input()
n=sorted(list(map(int,input().split())))
m=n[0]
a=set()
for x in range(1,int(m**.5)+1):
    if m%x==0:a|={x,m//x}
for c in sorted(list(a)):
    for k in n[1:]:
        if k%c:break
    else:print(c)

Submission status: Accepted

Solution code:
from math import sqrt

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

upper = min(ns)

for i in range(1, upper+1):
  judge = True
  for j in ns:
    if j % i != 0:
      judge = False
      break
  if judge == True:
    print(i)

Submission status: Accepted

Solution code:
from math import gcd
n = int(input())
if n == 2:
  a, b = map(int,input().split())
  g = gcd(a, b)
else:
  a, b, c = map(int,input().split())
  g = gcd(a, b)
  g = gcd(g, c)

lst = []
app = lst.append
for i in range(1, int(g ** (1/2)) + 1):
  if not g % i:
    if i ** 2 != g:
      app(i)
      app(g // i)
    else:
      app(i)
lst.sort()
for i in lst:
  print(i)

Submission status: Accepted

Solution code:
n=int(input())
Ans=[]
if n==2:
    l=input().split()
    a=int(l[0])
    b=int(l[1])
    if a>=b:
        for i in range(1,b+1):
            if b%i==0:
                if a%i==0:
                    Ans.append(i)
                else:
                    pass
            else:
                pass
    else:
        for i in range(1,a+1):
            if a%i==0:
                if b%i==0:
                    Ans.append(i)
                else:
                    pass
            else:
                pass
else:
    l=input().split()
    p=[]
    p.append(int(l[0]))
    p.append(int(l[1]))
    p.append(int(l[2]))
    c=max(p)
    p.remove(c)
    a=p[0]
    b=p[1]
    if a>=b:
        for i in range(1,b+1):
            if b%i==0:
                if a%i==0:
                    if c%i==0:
                        Ans.append(i)
                    else:
                        pass
                else:
                    pass
            else:
                pass
    else:
        for i in range(1,a+1):
            if a%i==0:
                if b%i==0:
                    if c%i==0:
                        Ans.append(i)
                    else:
                        pass
                else:
                    pass
            else:
                pass

for A in Ans:
    print(A)

Submission status: Accepted

Solution code:
def gcd(a, b):
    x, y = [a, b] if a > b else [b, a]
    while y:
        x, y = y, x%y
    return x

n = int(input())
nums = sorted(list(map(int, input().split(' '))))
loops = gcd(nums[0], nums[1])
print(1)
for x in range(2, loops+1):
    flg = True
    for num in nums:
        if num%x != 0:
            flg = False
            break
    if flg:
        print(x)

Submission status: Accepted

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

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

if n == 2:
    b = gcd(a[0], a[1])
    for i in range(1, b+1):
        if b%i == 0:
            print(i)
else:
    b = gcd(gcd(a[0], a[1]), a[2])
    for i in range(1, b+1):
        if b%i == 0:
            print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(n) for n in input().split()])
for i in range(1, a[0]+1):
    if n == 2:
        if a[0] % i == 0 and a[1] % i == 0:
            print(i)
    else:
        if a[0] % i == 0 and a[1] % i == 0 and a[2] % i == 0:
            print(i)

Submission status: Accepted

Solution code:
n = int(input())
nList = list(map(int,input().split()))
cdSetList= []
def cdSet(x,y):
    return {i for i in range(1, min(x,y)+1) if x%i==0 and y%i==0}

for i in range(len(nList)-1):
    cdSetList.append(cdSet(nList[i],nList[i+1]))
from functools import *
cdForAll = sorted(reduce(set.intersection, cdSetList))
for i in cdForAll:
    print(i)

Submission status: Accepted

Solution code:
# coding=utf-8


def gcd(n1, n2):
    if n1 < n2:
        n1, n2 = n2, n1

    if n1 == n2 or n2 == 0:
        return n1
    n1, n2 = n2, (n1 % n2)
    return gcd(n1, n2)


def make_divisor_list(number):
    divisor_list = []
    if number == 1:
        return [1]

    for i in range(1, number//2 + 1):
        if number % i == 0:
            divisor_list.append(i)
    divisor_list.append(number)
    return divisor_list


if __name__ == '__main__':
    N = int(input())
    number_list = list(map(int, input().split()))
    if N == 2:
        GCD = gcd(number_list[0], number_list[1])
    else:
        GCD = gcd(gcd(number_list[0], number_list[1]), number_list[2])
    [print(element) for element in make_divisor_list(GCD)]

Submission status: Accepted

Solution code:
def run():
    n = int(input())
    nls = sorted([int(i) for i in input().split()])
    result = []
    for i in range(1, nls[0] + 1):
        flag = 1
        for j in nls:
            if j % i:
                flag = 0
                break
            else:
                continue
        if flag:
            result.append(i)
    for i in result:
        print(i)

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
# AOJ 0583: Common Divisors
# Python3 2018.6.30 bal4u

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()))
g = gcd(a[0], a[1])
for i in range(2, len(a)): g = gcd(g, a[i])
for x in range(1, g+1, 1+(g&1)):
	if g%x == 0: print(x)

Submission status: Accepted

Solution code:
def factorize(n):
  ret = [1, n]
  for i in xrange(2, n):
    if i * i > n:
      break
    if n % i == 0:
      ret.append(i)
      if i * i != n:
        ret.append(n / i)
  return ret

n = input()
a = {}

for k in map(int, raw_input().split()):
  for f in factorize(k):
    if not f in a:
      a[f] = 0
    a[f] += 1

for k in sorted(a):
  if a[k] == n:
    print k

Submission status: Accepted

Solution code:
n=input()
lst=map(int,raw_input().split())
minNum=min(lst)
ans=[]
for i in xrange(2,minNum+1):
    for j in lst:
        #print i,j,j%i
        if (j % i) != 0:
            break
    else:
        ans.append(i)

print 1
for i in ans:
    print i

Submission status: Accepted

Solution code:
from fractions import gcd
n=input()
L=map(int,raw_input().split())
g=reduce(gcd,L)
for i in range(1,g):
    for t in L:
        if t%i!=0:
            break
    else:
        print i
print g

Submission status: Accepted

Solution code:
n=raw_input()
nums=[int(i) for i in raw_input().split(' ')]
print '\n'.join([str(i) for i in range(1,max(nums)) if max([j%i for j in nums])==0])

Submission status: Accepted

Solution code:
def gcd(m,n):
    r = m%n if n<m else n%m
    return min(m,n) if r==0 else gcd(n,r)
n = input()
x = map(int,raw_input().split())
g = gcd(x[0],x[1]) if n==2 else gcd(gcd(x[0],x[1]),x[2])
for i in xrange(1,g+1):
    if g%i==0: print i

Submission status: Accepted

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

n=input()
if n==2:
	a,b=map(int,raw_input().split())
	g=gcd(a,b)
else:
	a,b,c=map(int,raw_input().split())
	g=gcd(gcd(a,b),c)
for i in range(1,g+1):
		if gcd(i,g)==i:print i

Submission status: Accepted

Solution code:
from fractions import gcd
n=input()
L=map(int,raw_input().split())
g=reduce(gcd,L)
for i in range(1,g+1):
    if g%i==0:print i

Submission status: Accepted

Solution code:
from fractions import gcd
n=input()
L=map(int,raw_input().split())
g=reduce(gcd,L)
print "\n".join(map(str,filter(lambda x:g%x==0,range(1,g+1))))

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
a=reduce(gcd,a)
for i in range(1,a+1):
  if a%i==0:print(i)

Submission status: Accepted

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


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


if n == 3:
    x = gcd(gcd(l[0],l[1]),l[2])
else:
    x = gcd(l[0],l[1])


for i in range(1,x+1):
    if x % i == 0:
        print(i)

Submission status: Accepted

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


n = int(input())
num_list = list(map(int, input().split()))
tmp = num_list[0]
for i in range(n):
    tmp = gcd(tmp, num_list[i])

divisor_list = []
for i in range(1, int(tmp**0.5) + 1):
    if tmp % i == 0:
        divisor_list.append(i)
        if i != (tmp //i):
            divisor_list.append(tmp // i)
divisor_list.sort()
for element in divisor_list:
    print(element)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)

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

if n == 2:
    a,b = map(int,input().split())
    g = gcd(a,b)
else:
    a,b,c = map(int,input().split())
    g = gcd(a,b)
    g = gcd(g,c)

from collections import Counter
answers = [g]
primes = []
f = 2
while f**2<=g:
    if g%f==0:
        primes.append(f)
        g//=f
    else:
        f+=1
if g != 1:
    primes.append(g)
primes = Counter(primes)

for p,v in primes.items():
    tmp = []
    for e in range(1,v+1):
        for a in answers:
            tmp.append(a//(p**e))
    answers += tmp
answers.sort()
for a in answers:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
lst.sort(reverse=True)
comdiv = [1]
MAX = lst[0] // 2 + 1
for i in range(2, MAX + 1):
	if n == 2:
		if lst[0] % i == 0 and lst[1] % i == 0:
			comdiv.append(i)
	if n == 3:
		if lst[0] % i == 0 and lst[1] % i == 0 and lst[2] % i == 0:
			comdiv.append(i)

for j in comdiv:
	print(j)

Submission status: Accepted

Solution code:
import math
N = int(input())
ints = list(map(int,input().split()))

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

d = ints[0]
for i in range(1, N):
  d = gcd(d, ints[i])

res = []
for i in range(1, int(math.sqrt(d)+1)):
  if d % i == 0:
    if d // i == i:
      print(i)
    else:
      print(i)
      res.append(int(d//i))

for i in res[::-1]: print(i)

Submission status: Accepted

Solution code:
import math
i = int(input())

#入力の個数が2個なら2数の最大公約数を求め1から最大公約数までの数で約数を求める
if i == 2:
    a,b = map(int,input().split())
    num = math.gcd(a,b)
    for i in range(1,num + 1):
        if a % i == 0 and b % i == 0:
            print(i)

#入力の個数が3個なら2数の最大公約数を調べ最大公約数と3個目の最大公約数を調べ1から最大公約数までの数で約数を求める
else:
    a,b,c = map(int,input().split())
    num = math.gcd(a,b)
    num = math.gcd(num,c)
    for i in range(1,num + 1):
        if a % i == 0 and b % i == 0 and c % i ==0:
            print(i)

Submission status: Accepted

Solution code:
import sys
import math

n = int(sys.stdin.readline().rstrip())
nums = list(map(int, sys.stdin.readline().rstrip().split()))

g = nums[0]
for num in nums[1:]:
    g = math.gcd(g, num)

ans = set()
for i in range(1, int(math.sqrt(g)) + 1):
    if g % i == 0:
        ans.add(i)
        ans.add(g // i)

for n in sorted(ans):
    print(n)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from math import gcd
from functools import reduce
from pprint import pprint

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

# def gcd3(*numbers):
#     return reduce(gcd, numbers)

# def gcd3_list(numbers):
#     return reduce(gcd, numbers)

n = int(input())
numbers = list(myinput())

numbers.sort()
a = numbers[0]
b = numbers[1]
g = gcd(a,b)

if len(numbers)==2:
    ls = []
    for i in range(1,g+1):
        if a%i==0 and b%i==0:
            ls.append(i)
    for i in range(len(ls)):
        print(ls[i])
else:
    c = numbers[2]
    ls = []
    for i in range(1,g+1):
        if a%i==0 and b%i==0 and c%i==0:
            ls.append(i)
    for i in range(len(ls)):
        print(ls[i])

Submission status: Accepted

Solution code:

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

n = int(input())
if n == 2:
  a, b = map(int, input().split())
  diva = set(divisor(a))
  divb = set(divisor(b))
  div = list(diva&divb)
  div = sorted(div)
  for i in div:
    print(i)
else:
  a, b, c = map(int, input().split())
  diva = set(divisor(a))
  divb = set(divisor(b))
  divc = set(divisor(c))
  div = list(diva&divb&divc) 
  div = sorted(div)
  for i in div:
    print(i)

Submission status: Accepted

Solution code:
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
    
def di(z):
    divi = []
    for i in range(1 , int(z**0.5) +1 ):
        if z%i == 0:
            divi.append(i)
            if i != z//i:
                divi.append(z//i) 
    return divi
    
n = int(input())
a = list(map(int , input().split()))

g = a[0]
for i in range(n-1):
    g = gcd( g , a[i+1] )
    
a = di(g)
a = sorted(a)
for i in a:
    print(i)

Submission status: Accepted

Solution code:
def prime(N):
  factor_li = []
  for i in range(1, int(N**(1/2)//1)+1):
    if N%i == 0:
      factor_li.append(i)
      factor_li.append(N//i)
  return sorted(set(factor_li))

def run():
  n = int(input())
  a_li = sorted(map(int, input().split()))
  factor_li = prime(a_li[0])
  for factor in factor_li:
    for a in a_li[1:]:
      if a%factor != 0:
        break
    else:
      print(factor)
  
if __name__ == '__main__':
  run()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
m = LIST()
gcd_num = m[0]
for i in range(1, n):
  gcd_num = gcd(gcd_num, m[i])

def make_divisors(n):
   divisors = []
   for i in range(1, int(n**0.5)+1):
       if n % i == 0:
           divisors.append(i)
           if i != n // i:
               divisors.append(n//i)
   divisors.sort()
   return divisors

print("\n".join(map(str, make_divisors(gcd_num))))

Submission status: Accepted

Solution code:
def sky(a, b):
    if a > b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

n = int(input())
if n == 2:
    a, b = sorted(list(map(int, input().split())))
    s = sky(a, b)

else:
    a, b, c = sorted(list(map(int, input().split())))
    s = sky(a, b)
    s = sky(s, c)

i = 1
table = []
while i * i <= s:
    if s%i == 0:
        table.append(i)
        table.append(s//i)
    i += 1
table = sorted(list(set(table)))
for k in table:
    print(k)

Submission status: Accepted

Solution code:
from math import gcd

n=int(input())
nums=list(map(int,input().split()))
g=nums[0]
g=[gcd(g,i) for i in nums[1:]]
a=set()
for i in range(1,int(g[0]**0.5)+1):
    if g[0]%i==0:
        a.add(i)
        a.add(g[0]//i)
a=[print(i) for i in sorted(list(a))]

Submission status: Accepted

Solution code:
import math

n = int(input())
if n == 2:
	a,b = map(int, input().split())
else:
	a,b,c = map(int, input().split())

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

if n == 2:
	gcd = GCD(a,b)
else:
	gcd = GCD(GCD(a,b), c)

d = math.floor(gcd**(1/2))
ans = []
for i in range(1,d+1):
	if gcd % i == 0:
		ans.append(i)
		ans.append(gcd//i)

for a in sorted(set(ans)):
	print(a)

Submission status: Accepted

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

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def divisors(N: int) -> set:
    """ 約数の列挙・個数 """
    from math import sqrt

    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て
    for i in range(2, int(sqrt(N))+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

N = INT()
A = LIST()

gcds = 0
for a in A:
    gcds = gcd(gcds, a)

ans = sorted(divisors(gcds))
[print(a) for a in ans]

Submission status: Accepted

Solution code:
from math import gcd, sqrt
 
n = int(input())
A = [int(x) for x in input().split()]
 
g = A[0]
for a in A[1:]:
    g = gcd(g, a)
 
ans = set()
 
for i in range(1, int(sqrt(g)) + 1):
    if g % i == 0:
        ans.add(i)
        ans.add(g // i)
 
for a in sorted(ans):
    print(a)

Submission status: Accepted

Solution code:
#AOJのコース用からJOI2006用に編集
import math
n=int(input())
L=input().split( )
x=int(L[0])
y=int(L[1])
if n==3:
    z=int(L[2])
if x<y:
    w=x
    x=y
    y=w

while x%y!=0:
    w=y
    y=x%y
    x=w

if n==3:
    if z<y:
        w=z
        z=y
        y=w

    while z%y!=0:
        w=y
        y=z%y
        z=w

sup=int(math.sqrt(y))
Common=[]
Common2=[]
for i in range(sup):
    if y%(i+1)==0:
        Common.append(i+1)
        Common2.append(int(y/(i+1)))
l=len(Common)
for j in range(l):
    Common.append(Common2[l-j-1])

if int(y/sup)*sup==y and int(y/sup)==sup:
    del Common[l-1]

l=len(Common)
for j in range(l):
    print(Common[j])

Submission status: Accepted

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


n = int(input())
l = list(map(int,input().split()))
d = l[0]
for i in l:
    d = gcd(d,i)

ans = []
for i in range(1,d):
    if i**2>d:
        break
    if d==i**2:
        ans.append(i)
    elif d%i==0:
        ans.append(i)
        ans.append(d//i)
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
while len(a)>1:a.append(math.gcd(a.pop(-1),a.pop(-1)))
a=a[0]
for i in range(1,a+1):
    if a%i==0:print(i)