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: 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:
n = int(input())

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

    for i in range(1, min(small, large // 2)):
        if a % i == 0 and b % i == 0:
            print(i)

else:
    a, b, c = map(int, input().split())
    small = min(a, b, c)
    large = max(a, b, c)

    for i in range(1, min(small, large // 2)):
        if a % i == 0 and b % i == 0 and c % i == 0:
            print(i)

Submission status: Accepted

Solution code:
import sys
fin = sys.stdin.readline


# time complexity: O(√n)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# time complexity: O(√n)
def enumerate_divisors(n):
    prime_numbers = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            prime_numbers.add(i)
            if n % (n // i) == 0:
                prime_numbers.add(n // i)
        i += 1
    return prime_numbers
        

n = int(fin())
number_list = [int(elem) for elem in fin().split()]
common_gcd = number_list[0]
for number in number_list[1:]:
    common_gcd = gcd(common_gcd, number)

for divisor in sorted(enumerate_divisors(common_gcd)):
    print(divisor)

Submission status: Accepted

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

if len(li) == 2:
    for i in range(1, max(li) + 1):
        if li[0] % i == 0 and li[1] % i == 0:
            print(i)
else:
    for i in range(1, max(li) + 1):
        if li[0] % i == 0 and li[1] % i == 0 and li[2] % i == 0:
            print(i)

Submission status: Accepted

Solution code:
N = int(input())
num = map(int, input().split())
sNum = sorted(num)
for i in range(1,sNum[0] + 1):
    count = 0
    for en in sNum:
        if en % i == 0:
            count += 1
    
    if count == N :
        print(i)

Submission status: Accepted

Solution code:
n = int(input())
list = []

if n == 2:
    a, b = map(int, input().split())
    
    for i in range(1, a+1):
        if a%i == 0:
            list.append(i)
    
    for i in range(1, b+1):
        if b%i == 0:
            list.append(i)
    listDup = [x for x in set(list) if list.count(x) > 1]
    
if n == 3:
    a, b, c = map(int, input().split())
    
    for i in range(1, a+1):
        if a%i == 0:
            list.append(i)
    
    for i in range(1, b+1):
        if b%i == 0:
            list.append(i)
    
    for i in range(1, b+1):
        if b%i == 0:
            list.append(i)
            
    listDup = [x for x in set(list) if list.count(x) > 2]
    
listDup.sort()

for i in range(len(listDup)):
        print(listDup[i])

Submission status: Accepted

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

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

gcd0 = a[0]
for i in range(1,n):
    gcd0 = gcd(gcd0, a[i])
    
maxi = int(gcd0**(1/2))
ans0 = []
for i in range(1, maxi+1):
    if gcd0%i == 0:
        x, y = i, gcd0//i
        ans0.append(x)
        ans0.append(y)
ans = list(set(ans0))
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from math import sqrt
N = int(input())
a = list(map(int, input().split()))
gcd = a[0]
for n in a[1:]:
    while n > 0:
        gcd, n = n, gcd%n

divisors = [1, gcd]
append = divisors.append
for i in range(2, int(sqrt(gcd))+1):
    if gcd % i == 0:
        append(i)
        append(gcd//i)

print(*sorted(set(divisors)), sep="\n")

Submission status: Accepted

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

def gcd_list(l):
    d = l[0]
    for i in range(len(l) - 1):
        d = gcd(d, l[i + 1])
    return d

def divisor(n):
    #nの約数のリストを返す
    import math
    m = int(math.sqrt(n))
    ans = []
    for i in range(1, m + 1):
        if n % i == 0:
            if i < n //i:
                ans += [i, n // i]
            else:
                ans += [i]
    ans.sort()
    return ans

n = int(input())
d = gcd_list(list(map(int, input().split())))

common_divs = divisor(d)
for i in common_divs:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a,b):
    a,b=sorted([a,b])
    while a > 0:
        t=a
        a=b%a
        b=t
    return b

def dev(a):
    d=list()
    for i in range(1, a+1):
        if a%i==0:
            d.append(i)
    return d

n=int(input())
while True:
    try:
        x=sorted(list(map(int,input().split())))
        a=x.pop(0)
        b=x.pop(0)
        c=gcd(a,b)
        while len(x) > 0:
            a=c
            b=x.pop(0)
            c=gcd(a,b)
        for i in dev(c):
            print(i)
        quit()
    except ValueError:
        break

Submission status: Accepted

Solution code:
import math
input()
gcd=0
for i in map(int,input().split(" ")):
    gcd=math.gcd(gcd,i)
for i in range(1,gcd+1):
    if gcd%i==0:print(i)

Submission status: Accepted

Solution code:
n = int(input())
num = input()
num = num.split(" ")
divs = []

for i in range(n):
    num[i] = int(num[i])
num.sort()

for i in range(1,int(num[0]**(1/2))):
    if num[0]%i == 0:
        divs.append(i)
        divs.append(num[0]//i)
if num[0]%int(num[0]**(1/2)) == 0:
    divs.append(int(num[0]**(1/2)))
divs.sort()

for i in range(len(divs)):
    flag = 1
    for j in range(1,n):
        if num[j]%divs[i] != 0:
            flag = 0
            break
    if flag == 1:
        print(divs[i])

Submission status: Accepted

Solution code:
n = input()
ans = []
if n == 2:
	data = map(int, raw_input().split())
	hoge = min(data)
	for i in range(1, hoge + 1):
		if data[0] % i == 0:
			if data[1] % i == 0:
				ans.append(i)
	for j in range(len(ans)):
		print ans[j]

if n == 3:
	data = map(int, raw_input().split())
	hoge = min(data)
	for i in range(1, hoge + 1):
		if data[0] % i == 0:
			if data[1] % i == 0:
				if data[2] % i == 0:
					ans.append(i)
	for j in range(len(ans)):
		print ans[j]

Submission status: Runtime Error

Solution code:
n = int(input())
values = list(map(int, input().split()))
minv = min(vs)+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: Runtime Error

Solution code:
if __name__ == '__main__' :
    n = int(input())
    a,b = [int(i) for i in input().split(" ")]
    for i in range(1,min(a,b)+1):
        if((a % i == 0) and (b % i == 0)):
            print(i)

Submission status: Runtime Error

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

def 

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:
      anlis.append(an)
      break
  if an == 1:
    break
anlis.sort()
ans = ""
for j in anlis:
  ans += str(j)
  ans += " "
ans = ans[:-1]
print(ans)

Submission status: Runtime Error

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(list(a)):
    for k in n[1:]:
        if k%c:break
    else:print(c)