input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
n=int(eval(input()))
s=list(map(str,input().split()))
total=[]
for i in range(n):
if s[i] not in total:
total.append(s[i])
print(('Three' if len(total)==3 else 'Four'))
|
eval(input())
l=list(map(str,input().split()))
print(('Three' if len(set(l))==3 else 'Four'))
|
p03424
|
N = int(eval(input()))
S = list(map(str, input().split()))
A = 0
for i in range(N):
for j in range(N-1):
for k in range(N-2):
for l in range(N-3):
if S[i] != S[j+1] and S[j+1] != S[k+2]and S[k+2] != S[l+3] and S[l+3] != S[i] and S[j+1] != S[l+3] and S[i] != S[k+2]:
A = A+1
if A != 0:
print("Four")
else:
print("Three")
|
N = int(eval(input()))
S = list(map(str, input().split()))
if ("P"and "W" and "G" and "Y") in S:
print("Four")
else:
print("Three")
|
p03424
|
import sys
n, *s = sys.stdin.read().split()
def main():
return 'Four' if len(set(s)) == 4 else 'Three'
if __name__ == '__main__':
ans = main()
print(ans)
|
import sys
n, *s = sys.stdin.read().split()
def main():
print(('Four' if len(set(s)) == 4 else 'Three'))
if __name__ == '__main__':
main()
|
p03424
|
def main():
N = int(eval(input()))
A = [i for i in input().split()]
ans = ["Three", "Four"]
print((ans[0] if len(set(A)) == 3 else ans[1]))
if __name__ == '__main__':
main()
|
def main():
N = int(eval(input()))
A = {i for i in input().split()}
if "Y" in A:
print("Four")
else:
print("Three")
if __name__ == '__main__':
main()
|
p03424
|
n = int(eval(input()))
s = list(map(str,input().split()))
a = len(list(set(s)))
if a==3:
print("Three")
else:
print("Four")
|
n = int(eval(input()))
s = list(map(str,input().split()))
if "Y" in s:
print("Four")
else:
print("Three")
|
p03424
|
from collections import Counter
n = eval(input())
s = input().split()
ss = Counter(s)
print(('Three' if len(ss) == 3 else 'Four'))
|
n = eval(input())
s = set(input().split())
print(('Three' if len(s) == 3 else 'Four'))
|
p03424
|
n = int(eval(input()))
s = input().split()
s = set(s)
print(('Four' if len(s) == 4 else 'Three'))
|
n = int(eval(input()))
s = input().split()
print(('Four' if len(set(s)) == 4 else 'Three'))
|
p03424
|
n=int(eval(input()))
t = input().split()
count = []
memo = 0
for i in t:
if i in count:
continue
count.append(i)
memo += 1
if memo == 3:
print('Three')
else:
print('Four')
|
n = int(eval(input()))
s = list(map(str,input().split()))
if "Y" in s:
print("Four")
else:
print("Three")
|
p03424
|
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)
def solve(N, S):
if "Y" in S:
return "Four"
else:
return "Three"
def main():
N = int(eval(input()))
S = list(input().split())
print((solve(N, S)))
if __name__ == '__main__':
main()
|
#!/usr/bin/python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def main():
N = int(eval(input()))
S = list(input().split())
if "Y" in S:
print("Four")
else:
print("Three")
if __name__ == '__main__':
main()
|
p03424
|
n = int(eval(input()))
s = list(input().split())
P = s.count("P")
W = s.count("W")
G = s.count("G")
print(("Three" if n==P+W+G else "Four"))
|
eval(input())
s = list(map(str,input().split()))
print(("Three" if len(set(s))==3 else "Four"))
|
p03424
|
N = int(eval(input()))
l = list(map(str, input().split()))
s = set(l)
if len(s)==3:
print('Three')
else:
print('Four')
|
n = int(eval(input()))
l = list(input().split())
if len(set(l)) == 4:
print('Four')
else:
print('Three')
|
p03424
|
from collections import Counter
N = eval(input())
color_list = [i for i in input().split()]
result = len(Counter(color_list))
if result == 3:
result = 'Three'
elif result == 4:
result = 'Four'
print(result)
|
N = input()
color_list = [i for i in input().split()]
print('Four') if 'Y' in color_list else print('Three')
|
p03424
|
N = int(eval(input()))
S = input().split()
print(('Three' if len(set(S))==3 else 'Four'))
|
N = int(eval(input()))
S = set(input().split())
print(('Four' if len(S)==4 else 'Three'))
|
p03424
|
N = int(eval(input()))
S = list(map(str, input().split()))
candy_list = ['P', 'W', 'G', 'Y']
answer = 0
for i in range(4):
if candy_list[i] in S:
answer += 1
if answer == 3:
print('Three')
if answer == 4:
print('Four')
|
N = int(eval(input()))
S = list(map(str, input().split()))
if 'Y' in S:
answer = 'Four'
else:
answer = 'Three'
print(answer)
|
p03424
|
n = int(eval(input()))
flag = False
s = input().split(" ")
for c in s:
if(c == "Y"):
flag = True
if(flag):
print("Four")
else:
print("Three")
|
n = int(eval(input()))
s = input().split()
for i in s:
if(i == 'Y'):
print('Four')
exit()
print('Three')
|
p03424
|
N = int(eval(input()))
S = list(set(input().split()))
if(len(S) == 4):
print("Four")
else:
print("Three")
|
N = int(eval(input()))
S = input().split()
if(len(set(S)) == 4):
print("Four")
else:
print("Three")
|
p03424
|
n = int(eval(input()))
ls = [s.rstrip() for s in input().split()]
if ls.count('Y') > 0:
print('Four')
else:
print('Three')
|
eval(input())
ls = list(input().split())
if ls.count('Y') > 0:
print('Four')
else:
print('Three')
|
p03424
|
n=int(eval(input()))
print(("Three" if len(set(list(input().split())))==3 else "Four"))
|
n=eval(input())
print(("Three" if len(set(list(input().split())))==3 else "Four"))
|
p03424
|
eval(input())
s=input().split()
print(('Four' if 'Y' in s else 'Three'))
|
n=int(eval(input()))
s=set(input().split())
print(('Three' if len(s)==3 else 'Four'))
|
p03424
|
N = int(eval(input()))
S = list(map(str,input().split()))
if S.count("Y") == 0:
print("Three")
else:
print("Four")
|
N = int(eval(input()))
for i in (list(input().split())):
if i == "Y":
print("Four")
exit()
print("Three")
|
p03424
|
n=int(eval(input()))
s=list(input().split())
if len(set(s))==3:
print("Three")
if len(set(s))==4:
print("Four")
|
N = int(eval(input()))
A = input().split()
if len(set(A)) <= 3:
print("Three")
else:
print("Four")
|
p03424
|
N=int(eval(input()))
S=list(map(int,input().split()))
while len(S)!=1:
S.sort()
if S[1]%S[0]==0:
S.pop(1)
else:
S[1]=S[1]%S[0]
if S[0]==1:
print((1))
exit()
print((S[0]))
|
import math
N=int(eval(input()))
S=list(map(int,input().split()))
F=S[0]
for i in range(N-1):
F=math.gcd(F,S[i+1])
print(F)
|
p03127
|
#dpでできないかな?
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
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(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
n=I()
lis=LI()
lis=sorted(lis)
#print(lis)
for i in range(1,n):
lis[i]=lis[i]%lis[0]
lis.append(0)
lis=sorted(list(set(lis)))
while len(lis)>2:
for i in range(2,len(lis)):
lis[i]=lis[i]%lis[1]
lis.append(0)
lis=sorted(list(set(lis)))
#print(lis)
print((lis[-1]))
#print(lis[0])
|
#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(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(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)
|
p03127
|
import sys
sys.setrecursionlimit(10**6)
def f(a,*b):
if len(b)>1:
return f(a,f(*b))
b=b[0]
if b:
return f(b,a%b)
return a
n=int(eval(input()))
a=list(map(int,input().split()))
print((f(*a)))
|
def f(a,b):
if b:
return f(b,a%b)
return a
n=int(eval(input()))
a=list(map(int,input().split()))
p=f(a[0],a[1])
for i in a:
p=f(p,i)
print(p)
|
p03127
|
n = int(eval(input())) #整数
a = [int(i) for i in input().split() ]
a = list(set(a))
a.sort()
while len(a) > 1:
while (a[0] < a[1]):
a[1] %= a[0]
a = list(set(a))
a.sort()
if a[0] == 0:
a.pop(0)
if a[0] == 1:
break
print((a[0]))
|
n = int(eval(input())) #整数
a = [int(i) for i in input().split() ]
a = list(set(a))
a.sort()
while len(a) > 1:
while (a[0] < a[1]):
a[1] %= a[0]
x = a[1]
a[1] = a[0]
a[0] = x
if a[0] == 0:
a.pop(0)
if a[0] == 1:
break
print((a[0]))
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
denominator = 0
numerator = 1
while A[numerator] != 0:
A[denominator] = A[denominator] % A[numerator]
if A[denominator] == 0:
denominator += 1
numerator += 1
if denominator >= N or numerator >= N:
break
else:
denominator, numerator = numerator, denominator
print((min([a for a in A if a > 0])))
|
N = int(eval(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)
|
p03127
|
import math
N = int(eval(input()))
A = [int(x) for x in input().split()]
x = A[0]
for a in A:
x = math.gcd(x, a)
print(x)
|
import math
N = int(eval(input()))
A = [int(x) for x in input().split()]
ans = A[0]
for a in A[1:]:
ans = math.gcd(a, ans)
print(ans)
|
p03127
|
n = int(eval(input()))
a = list(map(int, input().split()))
if len(set(a)) == 1:
print((a[0]))
else:
a.sort()
count = 0
while(1):
count = count + 1
for i in range(1, len(a)):
x = a[i] + count
for j in range(i):
x = x % a[i-1-j]
if x == 0:
break
print(count)
|
n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(a, b):
if a <= b:
if b % a == 0:
return a
else:
return(gcd(b % a, a))
else:
if a % b == 0:
return b
else:
return(gcd(a % b, b))
ans = gcd(a[0], a[1])
for i in range(2, len(a)):
ans = gcd(ans, a[i])
print(ans)
|
p03127
|
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse=True)
a = A[0]
for i in range(1,N):
a = gcd(a,A[i])
print(a)
|
def gcd(a, b):
if b > a:
a,b = b,a
if b == 0:
return a
else:
return gcd(b, a % b)
N = int(eval(input()))
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
a = gcd(a,A[i])
print(a)
|
p03127
|
def divisor(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
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
ans = set(divisor(a[0]))
for i in range(1, n):
tmp = set(divisor(a[i]))
ans = ans & tmp
print((max(ans)))
if __name__ == '__main__':
main()
|
def main():
n = int(eval(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()
|
p03127
|
N=int(eval(input()))
A=list(map(int,input().split()))
while len(set(A))!=1:
#for i in range(2):
A.sort()
for i in range(len(A)-1):
if A.count(0):
A.remove(0)
break
A[i+1]=A[i+1]%A[0]
print((max(A)))
|
N=int(eval(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)
|
p03127
|
# import numpy as np
# import numpypy as np
import sys
import math
import string
import fractions
import re
import array
import copy
import functools
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
# from itertools import accumulate
# from collections import deque
import random
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def main():
n = int(eval(input()))
l = list(map(int, input().split()))
# eprint("=======================")
while True:
xx = min([x for x in l if x > 0])
l = [(tt if tt==xx else tt%xx) for tt in l]
# eprint(l)
if all(x==l[0] for x in l):
print(l[0])
return 0
if 1 in l:
print(1)
return 0
if sum(l)==xx:
print(xx)
return 0
# eprint("=======================")
print(xx)
return 0
if __name__ == '__main__':
main()
|
# import numpy as np
# import numpypy as np
import sys
import math
import string
import fractions
import re
import array
import copy
import functools
import operator
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
# from itertools import accumulate
# from collections import deque
import random
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def main():
n = int(eval(input()))
l = list(map(int, input().split()))
eprint("=======================")
while True:
xx = min([x for x in l if x > 0])
# eprint("min_index: "+str(min_index))
eprint("xx: "+str(xx))
flag = 0
for i in range(len(l)):
if l[i] == xx and flag == 0:
flag=1
else:
l[i] = l[i]%xx
# eprint(l)
if all(x==l[0] for x in l):
# eprint(l)
print(l[0])
return 0
if 1 in l:
print(1)
return 0
if sum(l)==xx:
print(xx)
return 0
eprint("=======================")
print(xx)
return 0
if __name__ == '__main__':
main()
|
p03127
|
n = int(eval(input()))
a = list(map(int,input().split()))
def f(a,b):
if b==0:
return a
else:
return f(b,a%b)
a = sorted(a)
ans = float('inf')
for i in range(len(a)-1):
for j in range(i+1,len(a)):
ans = min(ans,f(a[i],a[j]))
print(ans)
|
n = int(eval(input()))
a = list(map(int,input().split()))
memo = {}
def f(a,b):
if b==0:
return a
else:
return f(b,a%b)
a = sorted(a)
ans = float('inf')
for i in range(len(a)-1):
ans = min(ans,f(a[i],a[i+1]))
print(ans)
|
p03127
|
N=int(eval(input()))
HP=list(map(int,input().split()))
a=HP[0]
b=HP[1]
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
tmp=a
for i in range(1,N-1):
a=tmp
b=HP[i+1]
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
tmp=a
print(tmp)
|
import sys
N=int(eval(input()))
HP=list(map(int,input().split()))
a=HP[0]
b=HP[1]
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
tmp=a
for i in range(1,N-1):
a=tmp
b=HP[i+1]
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
tmp=a
if tmp==1:
print(tmp)
sys.exit()
print(tmp)
|
p03127
|
# coding: utf-8
import sys
# import bisect
# import math
# import itertools
# import numpy as np
"""Template"""
class IP:
"""
入力を取得するクラス
"""
def __init__(self):
self.input = sys.stdin.readline
def I(self):
"""
1文字の取得に使います
:return: int
"""
return int(self.input())
def S(self):
"""
1文字の取得(str
:return: str
"""
return self.input()
def IL(self):
"""
1行を空白で区切りリストにします(int
:return: リスト
"""
return list(map(int, self.input().split()))
def SL(self):
"""
1行の文字列を空白区切りでリストにします
:return: リスト
"""
return list(map(str, self.input().split()))
def ILS(self, n):
"""
1列丸々取得します(int
:param n: 行数
:return: リスト
"""
return [int(self.input()) for _ in range(n)]
def SLS(self, n):
"""
1列丸々取得します(str
:param n: 行数
:return: リスト
"""
return [self.input() for _ in range(n)]
def SILS(self, n):
"""
Some Int LineS
横に複数、縦にも複数
:param n: 行数
:return: list
"""
return [self.IL() for _ in range(n)]
def SSLS(self, n):
"""
Some String LineS
:param n: 行数
:return: list
"""
return [self.SL() for _ in range(n)]
class Idea:
def __init__(self):
pass
def HF(self, p):
"""
Half enumeration
半分全列挙です
pの要素の和の組み合わせを作ります。
ソート、重複削除行います
:param p: list : 元となるリスト
:return: list : 組み合わせられた和のリスト
"""
return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))
def Bfs2(self, a):
"""
bit_full_search2
bit全探索の改良版
全探索させたら2進数のリストと10進数のリストを返す
:return: list2つ : 1個目 2進数(16桁) 2個目 10進数
"""
# 参考
# https://blog.rossywhite.com/2018/08/06/bit-search/
# https://atcoder.jp/contests/abc105/submissions/4088632
value = []
for i in range(1 << len(a)):
output = []
for j in range(len(a)):
if self.bit_o(i, j):
"""右からj+1番目のiが1かどうか判定"""
# output.append(a[j])
output.append(a[j])
value.append([format(i, 'b').zfill(16), sum(output)])
value.sort(key=lambda x: x[1])
bin = [value[k][0] for k in range(len(value))]
val = [value[k][1] for k in range(len(value))]
return bin, val
def S(self, s, r=0, m=-1):
"""
ソート関係行います。色々な設定あります。
:param s: 元となるリスト
:param r: reversするかどうか 0=False 1=True
:param m: (2次元配列)何番目のインデックスのソートなのか
:return: None
"""
r = bool(r)
if m == -1:
s.sort(reverse=r)
else:
s.sort(reverse=r, key=lambda x: x[m])
def bit_n(self, a, b):
"""
bit探索で使います。0以上のときにTrue出します
自然数だからn
:param a: int
:param b: int
:return: bool
"""
return bool((a >> b & 1) > 0)
def bit_o(self, a, b):
"""
bit探索で使います。1のときにTrue出すよ
oneで1
:param a: int
:param b: int
:return: bool
"""
return bool(((a >> b) & 1) == 1)
def ceil(self, x, y):
"""
Round up
小数点切り上げ割り算
:param x: int
:param y: int
:return: int
"""
return -(-x // y)
def ave(self, a):
"""
平均を求めます
:param a: list
:return: int
"""
return sum(a) / len(a)
def gcd(self, x, y):
if y == 0:
return x
else:
return self.gcd(y, x % y)
"""ここからメインコード"""
def main():
# 1文字に省略
r, e = range, enumerate
ip = IP()
id = Idea()
"""この下から書いてね"""
n = ip.I()
a = ip.IL()
res = max(a)
for i in r(1, n):
res = min(res, id.gcd(a[0], a[i]))
print(res)
main()
|
# coding: utf-8
import sys
# import bisect
# import math
# import itertools
# import numpy as np
"""Template"""
class IP:
"""
入力を取得するクラス
"""
def __init__(self):
self.input = sys.stdin.readline
def I(self):
"""
1文字の取得に使います
:return: int
"""
return int(self.input())
def S(self):
"""
1文字の取得(str
:return: str
"""
return self.input()
def IL(self):
"""
1行を空白で区切りリストにします(int
:return: リスト
"""
return list(map(int, self.input().split()))
def SL(self):
"""
1行の文字列を空白区切りでリストにします
:return: リスト
"""
return list(map(str, self.input().split()))
def ILS(self, n):
"""
1列丸々取得します(int
:param n: 行数
:return: リスト
"""
return [int(self.input()) for _ in range(n)]
def SLS(self, n):
"""
1列丸々取得します(str
:param n: 行数
:return: リスト
"""
return [self.input() for _ in range(n)]
def SILS(self, n):
"""
Some Int LineS
横に複数、縦にも複数
:param n: 行数
:return: list
"""
return [self.IL() for _ in range(n)]
def SSLS(self, n):
"""
Some String LineS
:param n: 行数
:return: list
"""
return [self.SL() for _ in range(n)]
class Idea:
def __init__(self):
pass
def HF(self, p):
"""
Half enumeration
半分全列挙です
pの要素の和の組み合わせを作ります。
ソート、重複削除行います
:param p: list : 元となるリスト
:return: list : 組み合わせられた和のリスト
"""
return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))
def Bfs2(self, a):
"""
bit_full_search2
bit全探索の改良版
全探索させたら2進数のリストと10進数のリストを返す
:return: list2つ : 1個目 2進数(16桁) 2個目 10進数
"""
# 参考
# https://blog.rossywhite.com/2018/08/06/bit-search/
# https://atcoder.jp/contests/abc105/submissions/4088632
value = []
for i in range(1 << len(a)):
output = []
for j in range(len(a)):
if self.bit_o(i, j):
"""右からj+1番目のiが1かどうか判定"""
# output.append(a[j])
output.append(a[j])
value.append([format(i, 'b').zfill(16), sum(output)])
value.sort(key=lambda x: x[1])
bin = [value[k][0] for k in range(len(value))]
val = [value[k][1] for k in range(len(value))]
return bin, val
def S(self, s, r=0, m=-1):
"""
ソート関係行います。色々な設定あります。
:param s: 元となるリスト
:param r: reversするかどうか 0=False 1=True
:param m: (2次元配列)何番目のインデックスのソートなのか
:return: None
"""
r = bool(r)
if m == -1:
s.sort(reverse=r)
else:
s.sort(reverse=r, key=lambda x: x[m])
def bit_n(self, a, b):
"""
bit探索で使います。0以上のときにTrue出します
自然数だからn
:param a: int
:param b: int
:return: bool
"""
return bool((a >> b & 1) > 0)
def bit_o(self, a, b):
"""
bit探索で使います。1のときにTrue出すよ
oneで1
:param a: int
:param b: int
:return: bool
"""
return bool(((a >> b) & 1) == 1)
def ceil(self, x, y):
"""
Round up
小数点切り上げ割り算
:param x: int
:param y: int
:return: int
"""
return -(-x // y)
def ave(self, a):
"""
平均を求めます
:param a: list
:return: int
"""
return sum(a) / len(a)
def gcd(self, x, y):
if y == 0:
return x
else:
return self.gcd(y, x % y)
"""ここからメインコード"""
def main():
# 1文字に省略
r, e = range, enumerate
ip = IP()
id = Idea()
"""この下から書いてね"""
n = ip.I()
a = ip.IL()
res = 1000000010
for i in r(1, n):
res = min(res, id.gcd(a[0], a[i]))
print(res)
main()
|
p03127
|
# coding: utf-8
import sys
# import bisect
# import math
# import itertools
# import numpy as np
"""Template"""
class IP:
"""
入力を取得するクラス
"""
def __init__(self):
self.input = sys.stdin.readline
def I(self):
"""
1文字の取得に使います
:return: int
"""
return int(self.input())
def S(self):
"""
1文字の取得(str
:return: str
"""
return self.input()
def IL(self):
"""
1行を空白で区切りリストにします(int
:return: リスト
"""
return list(map(int, self.input().split()))
def SL(self):
"""
1行の文字列を空白区切りでリストにします
:return: リスト
"""
return list(map(str, self.input().split()))
def ILS(self, n):
"""
1列丸々取得します(int
:param n: 行数
:return: リスト
"""
return [int(self.input()) for _ in range(n)]
def SLS(self, n):
"""
1列丸々取得します(str
:param n: 行数
:return: リスト
"""
return [self.input() for _ in range(n)]
def SILS(self, n):
"""
Some Int LineS
横に複数、縦にも複数
:param n: 行数
:return: list
"""
return [self.IL() for _ in range(n)]
def SSLS(self, n):
"""
Some String LineS
:param n: 行数
:return: list
"""
return [self.SL() for _ in range(n)]
class Idea:
def __init__(self):
pass
def HF(self, p):
"""
Half enumeration
半分全列挙です
pの要素の和の組み合わせを作ります。
ソート、重複削除行います
:param p: list : 元となるリスト
:return: list : 組み合わせられた和のリスト
"""
return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))
def Bfs2(self, a):
"""
bit_full_search2
bit全探索の改良版
全探索させたら2進数のリストと10進数のリストを返す
:return: list2つ : 1個目 2進数(16桁) 2個目 10進数
"""
# 参考
# https://blog.rossywhite.com/2018/08/06/bit-search/
# https://atcoder.jp/contests/abc105/submissions/4088632
value = []
for i in range(1 << len(a)):
output = []
for j in range(len(a)):
if self.bit_o(i, j):
"""右からj+1番目のiが1かどうか判定"""
# output.append(a[j])
output.append(a[j])
value.append([format(i, 'b').zfill(16), sum(output)])
value.sort(key=lambda x: x[1])
bin = [value[k][0] for k in range(len(value))]
val = [value[k][1] for k in range(len(value))]
return bin, val
def S(self, s, r=0, m=-1):
"""
ソート関係行います。色々な設定あります。
:param s: 元となるリスト
:param r: reversするかどうか 0=False 1=True
:param m: (2次元配列)何番目のインデックスのソートなのか
:return: None
"""
r = bool(r)
if m == -1:
s.sort(reverse=r)
else:
s.sort(reverse=r, key=lambda x: x[m])
def bit_n(self, a, b):
"""
bit探索で使います。0以上のときにTrue出します
自然数だからn
:param a: int
:param b: int
:return: bool
"""
return bool((a >> b & 1) > 0)
def bit_o(self, a, b):
"""
bit探索で使います。1のときにTrue出すよ
oneで1
:param a: int
:param b: int
:return: bool
"""
return bool(((a >> b) & 1) == 1)
def ceil(self, x, y):
"""
Round up
小数点切り上げ割り算
:param x: int
:param y: int
:return: int
"""
return -(-x // y)
def ave(self, a):
"""
平均を求めます
:param a: list
:return: int
"""
return sum(a) / len(a)
def gcd(self, x, y):
if y == 0:
return x
else:
return self.gcd(y, x % y)
"""ここからメインコード"""
def main():
# 1文字に省略
r, e = range, enumerate
ip = IP()
id = Idea()
"""この下から書いてね"""
n = ip.I()
a = ip.IL()
res = 1000000010
for i in r(1, n):
res = min(res, id.gcd(a[0], a[i]))
print(res)
main()
|
def gcd(x, y):
# ユークリッドの互除法で最大公約数を見つける
if y == 0:
return x
else:
return gcd(y, x % y)
n = int(eval(input()))
a = list(map(int, input().split()))
# 最大公約数の1番小さい値を取る
# a[0]との最大公約数を全パターン取って、小さい方をansに入れる
ans = min(gcd(a[0], x) for x in a)
print(ans)
|
p03127
|
import bisect
import collections
n = int(eval(input()))
s = list(map(int,input().split()))
s.sort()
while len(s) > 1:#最も体力のあるのが攻撃を受ける
temp = s.pop()
for j in s:
damege = (temp//j)*j
if temp != 0 and temp != damege:
index = bisect.bisect_left(s,temp-damege)
s.insert(index,temp-damege)
print((s[0]))
|
import math
n = int(eval(input()))
a = list(map(int,input().split()))
tmp = a[0]
for i in range(1,len(a)):
tmp = math.gcd(tmp,a[i])
print(tmp)
|
p03127
|
from itertools import combinations
N=int(eval(input()))
A=[i for i in map(int,input().split())]
def gcd(x,y):
while y!=0:
x , y = y , x%y
return x
ans=1e10
for comb in combinations(A,2):
ans=min(ans,gcd(comb[0],comb[1]))
print(ans)
|
from itertools import combinations
N=int(eval(input()))
A=[i for i in map(int,input().split())]
def gcd(x,y):
while y!=0:
x , y = y , x%y
return x
ans=A[0]
for i in range(1,len(A)):
ans=min(ans,gcd(ans,A[i]))
print(ans)
|
p03127
|
n=int(eval(input()))
a_s=list(map(int,input().split()))
while True:
a_s=set(a_s)
a_s.discard(0)
a_s=list(a_s)
index=a_s.index(min(a_s))
for i in range(len(a_s)):
if i!=index and min(a_s)!=0:
a_s[i]=a_s[i]%min(a_s)
if len(a_s)==1:
break
print((sum(a_s)))
|
n=int(eval(input()))
a_s=list(map(int,input().split()))
def sakujo(a_list):
for i in range(len(a_list)):
if a_list[i]!=0:
end=i
break
return a_list[i:]
while True:
a_s.sort()
a_s=sakujo(a_s)
if len(a_s)==1:
break
for i in range(1,len(a_s)):
a_s[i]=a_s[i]%a_s[0]
print((sum(a_s)))
|
p03127
|
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for i in range(min(A),0,-1):
if all( A[c] % i == 0 for c in range(N)):
ans = i
break
print(ans)
|
N = int(eval(input()))
A = list(map(int,input().split()))
A = sorted(A) # とりあえず並び替えておく
tmp = 0
for i in range(N-1):
while A[i]>0:
tmp = A[i]
A[i] = A[i+1] % A[i]
A[i+1] = tmp
print((A[N-1]))
|
p03127
|
n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
while len(A) > 1:
a = [A[0]]
for i in range(1, len(A)):
if A[i]%A[0] == 0: continue
else: a.append(A[i]%A[0])
A = sorted(a)
print((A[0]))
|
n = int(eval(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]))
|
p03127
|
n, *a = list(map(int, open(0).read().split()))
a.sort()
ans = 1e10
for i in range(1, n):
x, y = a[0], a[i]
while y%x:
y -= y//x*x
x, y = y, x
ans = min(ans, x)
print(ans)
|
def gcd(a, b):
if(a==0): return b
if a<b: a,b=b,a
while b: a,b=b,a%b
return a
n, *a = list(map(int, open(0).read().split()))
g = 0
for i in a: g = gcd(g, i)
print(g)
|
p03127
|
n = int(eval(input()))
a = list(map(int,input().split()))
b = [0]*n
ans = min(a)
for j in range(min(a)):
for i in range(n):
b[i] = a[i]%ans
if max(b) == 0:
break
else:
ans = max(b)
print(ans)
|
n = int(eval(input()))
A = list(map(int,input().split()))
#ユーグリッドの互除法で、a,bを与えて、aをbで割ってあまりを計算する
#あまりがないときは、最後に割った数を返す(最大公約数)
#あまりがあるときは、bにあまりを入れて、再び計算する
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
x = A[0]
for i in A[1:]:
x = gcd(x,i)
print(x)
|
p03127
|
# 2019-11-12 15:53:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def main():
n, *a = (int(x) for x in sys.stdin.read().split())
ans = reduce(gcd, a)
print(ans)
if __name__ == "__main__":
main()
|
import sys
from functools import reduce
def gcd(a, b):
while b:
a, b = b, a % b
return abs(a)
n, *a = list(map(int, sys.stdin.read().split()))
def main():
return reduce(gcd, a)
if __name__ == '__main__':
ans = main()
print(ans)
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
R = A[0]
while True:
C = A.copy()
B = [A[0]] + [A[i+1] - A[i] for i in range(len(A)-1) if A[i+1] > A[i]]
B = list(set(B))
B.sort()
R = min(R, B[0])
if C == B:
break
elif R == 1:
break
else:
A = B
print(R)
|
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
R = A[0]
while True:
C = A.copy()
B = [A[0]] + [a for a in [A[i+1] % A[i] for i in range(len(A)-1)] if a > 0]
B = list(set(B))
B.sort()
R = min(R, B[0])
if C == B:
break
elif R == 1:
break
else:
A = B
print(R)
|
p03127
|
n=int(eval(input()))
a=list(map(int,input().split()))
import copy
for i in range(10**4):
a.sort()
wari=a[-2]
if wari==0:
print((a[-1]))
break
a[-1]=a[-1]%wari
|
n=int(eval(input()))
a=list(map(int,input().split()))
def gcd(a,b):
aa=max(a,b)
bb=min(a,b)
cc=aa%bb
return gcd(bb,cc) if cc else bb
p=gcd(a[0],a[1])
for i in range(2,n):
p=gcd(p,a[i])
print(p)
|
p03127
|
# -*- coding: utf-8 -*-
import fractions
N = int(eval(input()))
A = list(map(int, input().split()))
def calc(monsters):
if len(monsters) == 1:
return monsters[0]
min_monster = min(monsters)
min_index = monsters.index(min_monster)
new_monsters = []
for i in range(len(monsters)):
if i == min_index:
new_monsters.append(monsters[i])
remndr = monsters[i] % min_monster
if remndr != 0:
new_monsters.append(remndr)
return calc(new_monsters)
ans = calc(A)
print(ans)
|
# -*- coding: utf-8 -*-
N = int(eval(input()))
A = list(map(int, input().split()))
def calc(monsters):
if len(monsters) == 1:
return monsters[0]
min_monster = min(monsters)
min_index = monsters.index(min_monster)
new_monsters = []
for i in range(len(monsters)):
if i == min_index:
new_monsters.append(monsters[i])
remndr = monsters[i] % min_monster
if remndr != 0:
new_monsters.append(remndr)
return calc(new_monsters)
ans = calc(A)
print(ans)
|
p03127
|
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
N=int(eval(input()))
A=list(map(int,input().split()))
g=A[0]
for i in range(1,N):
g=gcd(g,A[i])
print(g)
|
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
while y:
x, y = y, x % y
return x
answer = A[0]
for i in range(1, N):
answer = gcd(A[i], answer)
print(answer)
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
while y:
x, y = y, x % y
return x
answer = A[0]
for i in range(1, N):
answer = gcd(A[i], answer)
print(answer)
|
import sys
input = sys.stdin.buffer.readline
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
while y:
x, y = y, x % y
return x
answer = A[0]
for i in range(1, N):
answer = gcd(A[i], answer)
print(answer)
|
p03127
|
from collections import Counter
def factor(N):
ret = []
i = 2
while N > 1:
if N % i == 0:
ret.append(i)
N //= i
else:
i += 1
return ret
def solve(N, As):
iter = Counter(factor(min(As)))
for a in As:
for k, v in list(iter.items()):
if a % k != 0:
iter[k] = 0
else:
count = 0
kk = k
while a % kk == 0:
kk *= k
count += 1
iter[k] = min(v, count)
d = 1
for k, v in list(iter.items()):
if v != 0:
d *= k ** v
return d
if __name__ == "__main__":
N = int(eval(input()))
As = list(map(int, input().split(" ")))
print((solve(N, As)))
|
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(eval(input()))
As = list(map(int, input().split(" ")))
print((solve(N, As)))
|
p03127
|
def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
minA = min(A)
while any(a % minA for a in A):
for i in range(N):
if A[i] % minA:
A[i] %= minA
minA = min(A)
print(minA)
if __name__ == '__main__':
main()
|
def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
g = A[0]
for a in A[1:]:
g = gcd(g, a)
print(g)
if __name__ == '__main__':
main()
|
p03127
|
N = int(eval(input()))
#A = [int(i) for i in input().split()]
A = list(map(int,input().split()))
def gcp(a,b):
if b == 0:
return a
else:
a,b = b,a%b
return gcp(a,b)
a = A[0]
for i in range(1,N):
a = gcp(a,A[i])
print(a)
|
N = int(eval(input()))
#A = [int(i) for i in input().split()]
A = list(map(int,input().split()))
def gcp(a,b):
if b == 0:
return a
else:
return gcp(b,a%b)
a = A[0]
for i in range(1,N):
a = gcp(a,A[i])
print(a)
|
p03127
|
N = int(eval(input()))
monsters = list(map(int, input().split()))
monsters.sort(reverse=True)
#print(monsters)
ans = min(monsters)
while ans > 0:
maxnum = max(monsters)
minnum = min(monsters)
maxidx = monsters.index(maxnum)
if maxnum % minnum == 0:
del monsters[maxidx]
if len(monsters) == 1:
print((monsters[0]))
quit()
else:
ans = maxnum % minnum
monsters[maxidx] = ans
|
N = int(eval(input()))
monsters = list(map(int, input().split()))
monsters.sort() # 昇順
minnum = monsters[0]
cnt = len(monsters)
minidx = 0
while cnt > 1:
for i in range(cnt - 1, 0, -1):
monsters[i] = monsters[i] % monsters[0]
if monsters[i] == 0:
del monsters[i]
elif monsters[i] == 1:
print('1')
quit()
workmin = min(monsters)
minidx = monsters.index(min(monsters))
monsters[minidx] = monsters[0]
monsters[0] = workmin
cnt = len(monsters)
print((monsters[0]))
|
p03127
|
N = int(eval(input()))
A = set(map(int, input().split()))
while len(A) > 1:
a = min(A)
A = set(x - a if x != a else a for x in A)
if 1 in A:
A = {1}
print((list(A)[0]))
|
N = int(eval(input()))
A = set(map(int, input().split()))
while len(A) > 1:
a = min(A)
A = set(x % a if x % a != 0 else a for x in A)
if 1 in A:
A = {1}
print((list(A)[0]))
|
p03127
|
N = int(eval(input()))
A = set(map(int, input().split()))
while len(A) > 1:
a = min(A)
A = set(x % a if x % a != 0 else a for x in A)
if 1 in A:
A = {1}
print((list(A)[0]))
|
N = int(eval(input()))
A = set(map(int, input().split()))
while len(A) > 1:
a = min(A)
A = set(x % a if x % a != 0 else a for x in A)
print((list(A)[0]))
|
p03127
|
n = int(eval(input()))
a = list(map(int, input().split()))
while True:
a.sort()
t = sum(a)
for i in range(1, len(a)):
if a[i] % a[0] == 0:
a[i] = a[0]
else:
a[i] = a[i] % a[0]
if sum(a) == t:
break
print((a[0]))
|
N = int(eval(input()))
A = list(map(int, input().split()))
while True:
A.sort()
t = sum(A)
for i in range(1, N):
if A[i] % A[0] == 0:
A[i] = A[0]
else:
A[i] = A[i] % A[0]
if sum(A) == t:
break
print((A[0]))
|
p03127
|
n,*h=list(map(int,open(0).read().split()))
while len(h)>1:
kh=set()
for x in h:
mn = min(h)
md=x%mn
if md!=0:
kh.add(md)
if len(kh)==mn-1:
break
kh.add(mn)
h=kh
print(mn)
|
def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
n,*h=list(map(int,open(0).read().split()))
gh=gcd(h[0],h[1])
for i in range(2,n):
gh=gcd(h[i],gh)
print(gh)
|
p03127
|
from math import gcd
n = int(eval(input()))
a = list(map(int,input().split()))
p = a[0]
for i in range(1,n):
p = gcd(p,a[i])
print(p)
|
from math import gcd
n = int(eval(input()))
a = list(map(int,input().split()))
ans = a[0]
for i in a[1:]:
ans = gcd(ans,i)
print(ans)
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 10 ** 10
while min(A) != ans:
ans = min(A)
for i, a_i in enumerate(A):
if a_i > ans:
A[i] = a_i % ans
if A[i] == 0:
del A[i]
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def gcd_arr(a):
ans = a[0]
for i, a_i in enumerate(a):
ans = gcd(ans, a_i)
return ans
print((gcd_arr(A)))
|
p03127
|
import random
N = int(eval(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]
elif N >= 6 and A[N-1] % A[N-6] != 0:
A[N-1] = A[N-1] % A[N-6]
elif N >= 7 and A[N-1] % A[N-7] != 0:
A[N-1] = A[N-1] % A[N-7]
elif N >= 8 and A[N-1] % A[N-8] != 0:
A[N-1] = A[N-1] % A[N-8]
elif N >= 9 and A[N-1] % A[N-9] != 0:
A[N-1] = A[N-1] % A[N-9]
elif N >= 10 and A[N-1] % A[N-10] != 0:
A[N-1] = A[N-1] % A[N-10]
elif N >= 11 and A[N-1] % A[N-11] != 0:
A[N-1] = A[N-1] % A[N-11]
elif N >= 12 and A[N-1] % A[N-12] != 0:
A[N-1] = A[N-1] % A[N-12]
elif N >= 13 and A[N-1] % A[N-13] != 0:
A[N-1] = A[N-1] % A[N-13]
elif N >= 14 and A[N-1] % A[N-14] != 0:
A[N-1] = A[N-1] % A[N-14]
elif N >= 15 and A[N-1] % A[N-15] != 0:
A[N-1] = A[N-1] % A[N-15]
elif N >= 16 and A[N-1] % A[N-16] != 0:
A[N-1] = A[N-1] % A[N-16]
elif N >= 17 and A[N-1] % A[N-17] != 0:
A[N-1] = A[N-1] % A[N-17]
elif N >= 18 and A[N-1] % A[N-18] != 0:
A[N-1] = A[N-1] % A[N-18]
elif N >= 19 and A[N-1] % A[N-19] != 0:
A[N-1] = A[N-1] % A[N-19]
elif N >= 20 and A[N-1] % A[N-20] != 0:
A[N-1] = A[N-1] % A[N-20]
elif N >= 21 and A[N-1] % A[N-21] != 0:
A[N-1] = A[N-1] % A[N-21]
elif N >= 22 and A[N-1] % A[N-22] != 0:
A[N-1] = A[N-1] % A[N-22]
elif N >= 23 and A[N-1] % A[N-23] != 0:
A[N-1] = A[N-1] % A[N-23]
elif N >= 24 and A[N-1] % A[N-24] != 0:
A[N-1] = A[N-1] % A[N-24]
elif N >= 25 and A[N-1] % A[N-25] != 0:
A[N-1] = A[N-1] % A[N-25]
random.shuffle(A)
list.append(min(A))
if iii > 100:
break
#print(list)
print((min(list)))
|
N = int(eval(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]
elif N >= 6 and A[N-1] % A[N-6] != 0:
A[N-1] = A[N-1] % A[N-6]
elif N >= 7 and A[N-1] % A[N-7] != 0:
A[N-1] = A[N-1] % A[N-7]
elif N >= 8 and A[N-1] % A[N-8] != 0:
A[N-1] = A[N-1] % A[N-8]
elif N >= 9 and A[N-1] % A[N-9] != 0:
A[N-1] = A[N-1] % A[N-9]
elif N >= 10 and A[N-1] % A[N-10] != 0:
A[N-1] = A[N-1] % A[N-10]
elif N >= 11 and A[N-1] % A[N-11] != 0:
A[N-1] = A[N-1] % A[N-11]
elif N >= 12 and A[N-1] % A[N-12] != 0:
A[N-1] = A[N-1] % A[N-12]
elif N >= 13 and A[N-1] % A[N-13] != 0:
A[N-1] = A[N-1] % A[N-13]
elif N >= 14 and A[N-1] % A[N-14] != 0:
A[N-1] = A[N-1] % A[N-14]
elif N >= 15 and A[N-1] % A[N-15] != 0:
A[N-1] = A[N-1] % A[N-15]
elif N >= 16 and A[N-1] % A[N-16] != 0:
A[N-1] = A[N-1] % A[N-16]
elif N >= 17 and A[N-1] % A[N-17] != 0:
A[N-1] = A[N-1] % A[N-17]
elif N >= 18 and A[N-1] % A[N-18] != 0:
A[N-1] = A[N-1] % A[N-18]
elif N >= 19 and A[N-1] % A[N-19] != 0:
A[N-1] = A[N-1] % A[N-19]
elif N >= 20 and A[N-1] % A[N-20] != 0:
A[N-1] = A[N-1] % A[N-20]
elif N >= 21 and A[N-1] % A[N-21] != 0:
A[N-1] = A[N-1] % A[N-21]
elif N >= 22 and A[N-1] % A[N-22] != 0:
A[N-1] = A[N-1] % A[N-22]
elif N >= 23 and A[N-1] % A[N-23] != 0:
A[N-1] = A[N-1] % A[N-23]
elif N >= 24 and A[N-1] % A[N-24] != 0:
A[N-1] = A[N-1] % A[N-24]
elif N >= 25 and A[N-1] % A[N-25] != 0:
A[N-1] = A[N-1] % A[N-25]
elif N >= 26 and A[N-1] % A[N-26] != 0:
A[N-1] = A[N-1] % A[N-26]
elif N >= 27 and A[N-1] % A[N-27] != 0:
A[N-1] = A[N-1] % A[N-27]
elif N >= 28 and A[N-1] % A[N-28] != 0:
A[N-1] = A[N-1] % A[N-28]
elif N >= 29 and A[N-1] % A[N-29] != 0:
A[N-1] = A[N-1] % A[N-25]
elif N >= 30 and A[N-1] % A[N-30] != 0:
A[N-1] = A[N-1] % A[N-30]
elif N >= 31 and A[N-1] % A[N-31] != 0:
A[N-1] = A[N-1] % A[N-31]
elif N >= 32 and A[N-1] % A[N-32] != 0:
A[N-1] = A[N-1] % A[N-32]
elif N >= 33 and A[N-1] % A[N-33] != 0:
A[N-1] = A[N-1] % A[N-33]
elif N >= 34 and A[N-1] % A[N-34] != 0:
A[N-1] = A[N-1] % A[N-34]
elif N >= 35 and A[N-1] % A[N-35] != 0:
A[N-1] = A[N-1] % A[N-35]
elif N >= 36 and A[N-1] % A[N-36] != 0:
A[N-1] = A[N-1] % A[N-36]
A = sorted(A)
list.append(min(A))
if iii > 128:
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)))
|
p03127
|
N = int(eval(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]
elif N >= 6 and A[N-1] % A[N-6] != 0:
A[N-1] = A[N-1] % A[N-6]
elif N >= 7 and A[N-1] % A[N-7] != 0:
A[N-1] = A[N-1] % A[N-7]
elif N >= 8 and A[N-1] % A[N-8] != 0:
A[N-1] = A[N-1] % A[N-8]
elif N >= 9 and A[N-1] % A[N-9] != 0:
A[N-1] = A[N-1] % A[N-9]
elif N >= 10 and A[N-1] % A[N-10] != 0:
A[N-1] = A[N-1] % A[N-10]
elif N >= 11 and A[N-1] % A[N-11] != 0:
A[N-1] = A[N-1] % A[N-11]
elif N >= 12 and A[N-1] % A[N-12] != 0:
A[N-1] = A[N-1] % A[N-12]
elif N >= 13 and A[N-1] % A[N-13] != 0:
A[N-1] = A[N-1] % A[N-13]
elif N >= 14 and A[N-1] % A[N-14] != 0:
A[N-1] = A[N-1] % A[N-14]
elif N >= 15 and A[N-1] % A[N-15] != 0:
A[N-1] = A[N-1] % A[N-15]
elif N >= 16 and A[N-1] % A[N-16] != 0:
A[N-1] = A[N-1] % A[N-16]
elif N >= 17 and A[N-1] % A[N-17] != 0:
A[N-1] = A[N-1] % A[N-17]
elif N >= 18 and A[N-1] % A[N-18] != 0:
A[N-1] = A[N-1] % A[N-18]
elif N >= 19 and A[N-1] % A[N-19] != 0:
A[N-1] = A[N-1] % A[N-19]
A = sorted(A)
list.append(min(A))
if iii > 128:
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)))
|
N = int(eval(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]
elif N >= 6 and A[N-1] % A[N-6] != 0:
A[N-1] = A[N-1] % A[N-6]
elif N >= 7 and A[N-1] % A[N-7] != 0:
A[N-1] = A[N-1] % A[N-7]
elif N >= 8 and A[N-1] % A[N-8] != 0:
A[N-1] = A[N-1] % A[N-8]
elif N >= 9 and A[N-1] % A[N-9] != 0:
A[N-1] = A[N-1] % A[N-9]
elif N >= 10 and A[N-1] % A[N-10] != 0:
A[N-1] = A[N-1] % A[N-10]
A = sorted(A)
list.append(min(A))
if iii > 96:
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)))
|
p03127
|
N = int(eval(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]
elif N >= 6 and A[N-1] % A[N-6] != 0:
A[N-1] = A[N-1] % A[N-6]
elif N >= 7 and A[N-1] % A[N-7] != 0:
A[N-1] = A[N-1] % A[N-7]
elif N >= 8 and A[N-1] % A[N-8] != 0:
A[N-1] = A[N-1] % A[N-8]
elif N >= 9 and A[N-1] % A[N-9] != 0:
A[N-1] = A[N-1] % A[N-9]
elif N >= 10 and A[N-1] % A[N-10] != 0:
A[N-1] = A[N-1] % A[N-10]
A = sorted(A)
list.append(min(A))
if iii > 96:
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)))
|
N = int(eval(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)))
|
p03127
|
import math
n = int(eval(input()))
A = tuple(map(int, input().split()))
g = A[0]
for a in A[1:]:
g = math.gcd(g, a)
print(g)
|
n = int(eval(input()))
A = tuple(map(int, input().split()))
ma = min(A)
while True:
ra = set([a%ma for a in A if a%ma > 0])
if len(ra) == 0:
print(ma)
break
minra = min(ra)
if ma == minra:
print(ma)
break
ma = minra
|
p03127
|
N = int(eval(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(mini)
|
N = int(eval(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]))
|
p03127
|
def INT():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
from collections import deque
N = INT()
A = LI()
A.sort()
while True:
mod = A[0]
flg = True
ans = A[0]
tmp = deque([A[0]])
if ans == 1:
print(ans)
break
for i in range(1, len(A)):
A[i] %= mod
if A[i] != 0 and flg:
flg = False
if A[i] == 0:
continue
tmp.append(A[i])
if flg:
print(ans)
break
A = sorted(tmp)
|
def INT():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
from math import gcd
N = INT()
A = LI()
A.sort()
ans = A[0]
all_can_div = True
for i in range(1, N):
A[i] = gcd(A[i], ans)
if A[i] != ans and all_can_div:
all_can_div = False
print((ans if all_can_div else min(A)))
|
p03127
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
#%%
# n, a = 4, [2, 10, 8, 40]
#%%
#%%
#%%
while len(a) >= 2:
a.sort()
for i in range(len(a) -1, 0, -1):
a[i] = a[i] % a[0]
if a[i] == 0:
a.remove(a[i])
#%%
print((a[0]))
#%%
|
n = int(eval(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)
|
p03127
|
import sys
sys.setrecursionlimit(1000000)
def gcd(i,j):
if i>j:
i,j=j,i
if j%i==0:
return i
return gcd(j-i,i)
n=int(eval(input()))
l=[int(i) for i in input().split()]
g=gcd(l[0],l[1])
for i in range(2,len(l)):
g=gcd(g,l[i])
print(g)
|
import sys
sys.setrecursionlimit(1000000)
def gcd(i,j):
if i>j:
i,j=j,i
if j%i==0:
return i
return gcd(j-i,i)
n=int(eval(input()))
l=[int(i) for i in input().split()]
l.sort()
g=gcd(l[0],l[1])
for i in range(2,len(l)):
g=gcd(g,l[i])
print(g)
|
p03127
|
import itertools
import copy
def main():
N = int(eval(input()))
A = set(list(map(int, input().split())))
com0 = None
while True:
com = list(itertools.combinations(A,2))
if com0 == com:
break
com0 = copy.copy(com)
for q in com:
if q[0] != 0 and q[1] != 0:
if q[0] > q[1]:
a1 = q[1]
a2 = q[0]
else:
a1 = q[0]
a2 = q[1]
a = a2 % a1
if a == 1:
print((1))
return
elif a == 0: # a2はa1の倍数
if a2 in A:
A.remove(a2)
else:
A.add(a)
#print(A)
print((min(A)))
main()
|
def gcm(a,b):
while b != 0:
a, b = b, a % b
return a
def gcm_list(a):
ans = a[0]
l = len(a)
for i in range(1, l):
ans = gcm(ans, a[i])
return ans
N = int(eval(input()))
A = list(map(int, input().split()))
print((gcm_list(A)))
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
while A[-2] != 0:
A[-1] -= A[-2] * (A[-1] // A[-2])
A.sort()
print((A[-1]))
|
N = int(eval(input()))
A = list(map(int, input().split()))
while len(A) > 1:
minA = min(A)
tempA = []
tempA.append(minA)
for a in A:
mod = a % minA
if mod != 0:
tempA.append(mod)
A = tempA
print((A[0]))
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
while len(A) > 1:
minA = min(A)
tempA = []
tempA.append(minA)
for a in A:
mod = a % minA
if mod != 0:
tempA.append(mod)
A = tempA
print((A[0]))
|
N = int(eval(input()))
A = set(map(int, input().split()))
while len(A) > 1:
minA = min(A)
tempA = set()
tempA.add(minA)
for a in A:
mod = a % minA
if mod != 0:
tempA.add(mod)
A = tempA
print((list(A)[0]))
|
p03127
|
N = int(eval(input()))
A = set(map(int, input().split()))
while len(A) > 1:
minA = min(A)
tempA = set()
tempA.add(minA)
for a in A:
mod = a % minA
if mod != 0:
tempA.add(mod)
A = tempA
print((list(A)[0]))
|
N = int(eval(input()))
A = list(map(int, input().split()))
while len(A) > 1:
minA = min(A)
tempA = []
tempA.append(minA)
for a in A:
mod = a % minA
if mod > 0:
tempA.append(mod)
A = tempA
print((A[0]))
|
p03127
|
from queue import PriorityQueue
N = int(eval(input()))
A = list(map(int, input().split()))
q = PriorityQueue()
for a in A:
q.put(a)
x = q.get()
while not q.empty():
y=q.get()
if y == 0:
continue
q.put(x % y)
x = y
print(x)
|
from queue import PriorityQueue
N = int(eval(input()))
A = list(map(int, input().split()))
q = PriorityQueue()
for a in A:
q.put(-a)
x = -q.get()
while not q.empty():
y = -q.get()
if y == 0:
break
q.put(-(x % y))
x = y
print(x)
|
p03127
|
import sys
n = int(eval(input()))
a = list(map(int, input().split()))
sys.setrecursionlimit(10 ** 5)
def cut(l):
l.sort()
nokori = [l[0]]
for i in range(1, len(l)):
b = l[i] % l[0]
if b != 0:
nokori.append(b)
if len(nokori) != 1:
return cut(nokori)
return nokori[0]
print((cut(a)))
|
import sys
n = int(eval(input()))
al = list(map(int, input().split()))
sys.setrecursionlimit(10 ** 5)
def gcd(a, b):
if b < a:
a, b = b, a
if b % a == 0:
return a
else:
return gcd(a, b % a)
def gcdl(num, n):
ans = num[0]
for i in range(n):
ans = gcd(ans, num[i])
return ans
print((gcdl(al, n)))
|
p03127
|
N = int(eval(input()))
A = [int(_) for _ in input().split()]
m = min(A)
if m == 1:
print(m)
else:
while m > 0:
m = min(A)
for i in range(0,len(A)):
if A[i] != m:
A[i] = A[i]%m
z = A.count(0)
for j in range(z):
A.remove(0)
if A.count(1) >= 1:
m = 1
break
else:
if [_%min(A) for _ in A].count(0) == len(A):
m = min(A)
break
print(m)
|
N = int(eval(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)
|
p03127
|
N = int(eval(input()))
A = list(map(int,input().split()))
def gcd(a,b):
while b!=0:
a,b=b,a%b
return a
gcd_a = A[0]
for i in A:
gcd_a = gcd(gcd_a,i)
print(gcd_a)
|
from math import gcd
N = int(eval(input()))
A = list(map(int,input().split()))
g = A[0]
for i in A:
g = gcd(g,i)
print(g)
|
p03127
|
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChar():
return eval(input())
def readChars():
return input().split()
n = readInt()
a = list(set(readInts()))
if len(a)==1:
print((a[0]))
exit()
odd = []
even = []
from math import gcd
d = a[0]
for i in a:
d = gcd(i,d)
print(d)
|
import math;eval(input());a=list(map(int,input().split()));d=a[0]
for i in a:d=math.gcd(i,d)
print(d)
|
p03127
|
n=int(eval(input()))
l=sorted(list(map(int,input().split())))
m=min(l)
l2=[]
l3=[]
for i in range(1,int(m**(1/2)+1)):
if m%i==0:
l2.append(i)
if i!=m//i:
l2.append(m//i)
for i in l2:
b=True
for j in l:
if j%i==0:
pass
else:
b=False
if b:
l3.append(i)
print((max(l3)))
|
def gcd(n,m):
a=min(n,m)
b=max(n,m)
while a!=0:
b,a=a,b%a
return b
n=int(eval(input()))
l=list(map(int,input().split()))
ans=l[0]
for i in range(1,n):
ans=gcd(ans,l[i])
print(ans)
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)
def judge(tmp_one, tmp_two):
flg = 1
while flg:
if tmp_two%tmp_one == 0:
tmp_two = tmp_one
else:
tmp_two = tmp_two%tmp_one
if tmp_one%tmp_two == 0:
tmp_one = tmp_two
else:
tmp_one = tmp_one%tmp_two
if tmp_one == tmp_two:
flg = 0
return tmp_one
tmp_one = As[0]
for i in range(1, N):
if i == N - 1:
tmp_two = As[i]
elif As[i] != As[0]:
tmp_two = As[i]
break
ans = judge(tmp_one, tmp_two)
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(n, m):
if n < m:
temp = n
n = m
m = temp
def ecd(n, m):
if n % m == 0:
return m
else:
temp = n % m
a = ecd(m, temp)
return a
return ecd(n, m)
temp = gcd(A[0], A[1])
for i in range(0, N-1):
temp = gcd(temp, A[i])
print(temp)
|
p03127
|
n = int(eval(input()))
a = list(map(int,input().split()))
while len(a)!=1:
a = sorted(a)
a = [i%min(a) for i in a[1:]]+[min(a)]
a = [i for i in a if i!=0]
print((min(a)))
|
n = int(eval(input()))
a = list(map(int,input().split()))
def gcd(x,y):
if x<y:
x,y = y,x
if y==0:
return x
if x%y==0:
return y
else:
return gcd(y,x%y)
ans = a[0]
for i in a:
ans = gcd(ans,i)
print(ans)
|
p03127
|
def gcd(a,b):
if a < b:
return gcd(b,a)
else:
if a%b == 0:
return b
else:
return gcd(b,a%b)
N = int(eval(input()))
src = sorted(list(map(int,input().split())))
ans = src[0]
for i in range(1,N)[::-1]:
ans = gcd(ans,src[i])
print(ans)
|
def Gcd(a,b):
if a < b:
return Gcd(b,a)
else:
if a%b:
return Gcd(b,a%b)
else:
return b
N = int(eval(input()))
arr = list(map(int,input().split()))
gcd = arr[0]
for i in arr:
gcd = Gcd(gcd,i)
print(gcd)
|
p03127
|
def gcd(x,y):
if y==0:
return x
else:
return gcd(y,x%y)
n=int(eval(input()))
a=list(map(int,input().split()))
a=list(sorted(a))
g=a[0]
for aa in a:
g=gcd(g,aa)
print(g)
|
def gcd(x, y):
if y == 0: return x
return gcd(y, x % y)
N = int(eval(input()))
a = list(map(int, input().split()))
g = a[0]
for aa in a:
g = gcd(g, aa)
print(g)
|
p03127
|
from queue import PriorityQueue
N = int(eval(input()))
A = list(map(int, input().split()))
q = PriorityQueue()
for a in A:
q.put(-a)
x = -q.get()
while not q.empty():
y = -q.get()
if y == 0:
break
q.put(-(x % y))
x = y
print(x)
|
from queue import PriorityQueue
N = int(eval(input()))
A = list(map(int, input().split()))
q = PriorityQueue()
for a in A:
q.put(a)
x = q.get()
while not q.empty():
y=q.get()
if y == 0:
continue
q.put(x % y)
x = y
print(x)
|
p03127
|
from math import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n-1):
a[i+1] = gcd(a[i], a[i+1])
print((a[n-1]))
|
from math import gcd
n=int(eval(input()))
a=list(map(int,input().split()))
res=a[0]
for i in range(1,n):
res=gcd(res,a[i])
print(res)
|
p03127
|
import math
def process(number_list):
left, point = number_list[0], number_list[-2]
if left == 1:
print((1))
return 0
yojo = number_list[-1] % left
point -= yojo
right = left * (math.ceil(point / left) - 1) + yojo
if right == 0:
number_list.pop(-1)
if len(number_list) == 1:
print((number_list[0]))
return 0
else:
number_list[-1] = right
number_list.sort()
return number_list
def main():
num = int(eval(input()))
number_list = list(map(int, input().split()))
number_list.sort()
while 1:
number_list = process(number_list)
if number_list == 0:
break
if __name__ == '__main__':
main()
|
import math
def process(number_list):
left, point = number_list[0], number_list[-2]
if left == 1:
print((1))
return 0
right = number_list[-1] % left
number_list.pop(-1)
if right == 0:
if len(number_list) == 1:
print((number_list[0]))
return 0
else:
number_list.insert(0, right)
return number_list
def main():
num = int(eval(input()))
number_list = list(map(int, input().split()))
number_list.sort()
while 1:
number_list = process(number_list)
if number_list == 0:
break
if __name__ == '__main__':
main()
|
p03127
|
#!usr/bin/env python3
from collections import defaultdict
import math
import bisect
import random
def LI(): return list(map(int, input().split()))
def II(): return int(eval(input()))
def LS(): return input().split()
def S(): return list(eval(input()))
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007
#A
#B
#C
def gcd(a,b):
if a == 0:
return b
return gcd(b%a,a)
n = II()
a = LI()
ans = a[0]
for i in range(1,n):
ans = gcd(ans,a[i])
print(ans)
#D
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
|
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = SR()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,b = LI()
if b%a == 0:
print((a+b))
else:
print((b-a))
return
#B
def B():
n,m = LI()
d = defaultdict(int)
for i in range(n):
l = LI()
for j in range(1,len(l)):
d[l[j]] += 1
ans = 0
for i in list(d.values()):
if i == n:
ans += 1
print(ans)
return
#C
def C():
def gcd(a,b):
if a == 0:
return b
return gcd(b%a,a)
n = I()
a = LI()
g = a[0]
for i in range(1,n):
g = gcd(g,a[i])
print(g)
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == "__main__":
C()
|
p03127
|
def gcd(a, b):
while b > 0:
a, b = b, a%b
return a
n = int(eval(input()))
enemy = list(set(map(int,input().split())))
if len(enemy)==1:
print((enemy[0]))
else:
enemy.sort()
min_n = 10**10
for i in range(len(enemy)-1):
min_n = min(min_n,gcd(enemy[i],enemy[i+1]))
print(min_n)
|
def gcd(x,y):
if x%y==0: return y
else: return gcd(y,x%y)
n = int(eval(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)
|
p03127
|
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
gcd = a[-1]
def Euclid(n1,n2):
if n1 % n2 == 0:
return n2
return Euclid(n2,n1%n2)
for i in range(n-1):
gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)
|
n = int(eval(input()))
a = list(map(int,input().split()))
gcd = a[-1]
def Euclid(n1,n2):
if n1 % n2 == 0:
return n2
return Euclid(n2,n1%n2)
for i in range(n-1):
gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)
|
p03127
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect
def solve():
n = int(eval(input()))
al = [int(i) for i in input().split()]
al.sort()
while len(al) > 1:
p = al[-1] % sum(al[:-1])
q = al[-1]
al = al[:-1]
if p == 0:
continue
if p == q:
q -= al[-1]
if q <= 0:
continue
p = q
bisect.insort(al, p)
print((al[0]))
if __name__=="__main__":
solve()
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def gcd(a, b):
if a < b:
a,b = b,a
while b > 0:
r = a % b
a,b = b,r
return a
def arrgcd(a):
alen = len(a)
if alen == 3:
return gcd(a[0], gcd(a[1], a[2]))
elif alen == 2:
return gcd(a[0], a[1])
elif alen == 1:
return a[0] # 最初から1つ
elif alen == 0:
return 0
else:
return gcd(arrgcd(a[:alen//2]), arrgcd(a[alen//2:]))
def solve():
n = int(eval(input()))
al = [int(i) for i in input().split()]
print((arrgcd(al)))
if __name__=="__main__":
solve()
|
p03127
|
# 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:
monster[1] %= monster[0]
if monster[1] == 0:
monster.pop(1)
monster.sort()
print((monster[0]))
|
# 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]))
|
p03127
|
N=int(eval(input()))
L=list(map(int,input().split()))
def f(l, s):
return s if l % s == 0 else f(s, l % s)
z = f(max(L), min(L))
for i in L:
z=f(i,z)
for i in range(1,10**6):
if max(L)>=i and i%z==0:
print(i)
exit()
print(z)
|
N=int(eval(input()))
L=list(map(int,input().split()))
def f(l, s):
return s if l % s == 0 else f(s, l % s)
z = f(max(L), min(L))
for i in L:
z=f(i,z)
ans=10000000000
for i in range(len(L)):
if L[i]%z==0:
pass
elif L[i]%z<ans:
ans=L[i]%z
if ans==10000000000:
print(z)
else:
print(ans)
|
p03127
|
n = int(eval(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]))
|
n = int(eval(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]))
|
p03127
|
n = int(eval(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]))
|
n = int(eval(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]))
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
x=0
key = min(A)
while x==0:
for i in range(N):
if int(A[i]%key)==0:
A[i]=key
else:
A[i]=A[i]%key
if min(A)==key:
print(key)
break
else:
key = min(A)
|
N = int(eval(input()))
List = list(map(int, input().split()))
while len(List)!=1:
m = min(List)
List = [e%m for e in List]
List = [e for e in List if e>0]
List.append(m)
print(m)
|
p03127
|
n = int(eval(input()))
monster = set(map(int,input().split()))
monster = sorted(list(monster))
if len(monster)==1:
print((monster[0]))
exit()
while True:
tmp = int(monster[-1]/monster[-2])
monster[-1]-=monster[-2]*tmp
monster = sorted(monster)
if monster[-2]==0:
print((monster[-1]))
exit()
|
def gcd(a, b):
while b:
a, b = b, a % b
return a
n = int(eval(input()))
monster = sorted(list(map(int,input().split())))
ans = []
for i in range(n-1):
g = gcd(monster[i], monster[i+1])
ans.append(g)
print((min(ans)))
|
p03127
|
def gcd(x,y):
while y>0:
x,y = y,x%y
return x
N = int(eval(input()))
A = list(map(int,input().split()))
x = A[0]
for i in range(1,N):
x = gcd(x,A[i])
print(x)
|
def gcd(x,y):
while y>0:
x,y = y,x%y
return x
N = int(eval(input()))
A = list(map(int,input().split()))
cmin = A[0]
for i in range(1,N):
cmin = gcd(cmin,A[i])
print(cmin)
|
p03127
|
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
for i in range(1,n):
while a[i]%a[0] != 0:
a[0],a[i] = a[i]%a[0],a[0]
else:
ans = a[0]
print(ans)
|
n = int(eval(input()))
a = list(map(int,input().split()))
for i in range(1,n):
while a[i]%a[0] != 0:
a[0],a[i] = a[i]%a[0],a[0]
else:
ans = a[0]
print(ans)
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
# A内の整数値を用いて作られる最小の整数を求めよ、という問題
def gcd(a, b):
"""
自然数a, b の最大公約数を求める
"""
if b == 0:
return a
else:
return gcd(b, a % b)
ans = float('inf')
for i in range(N):
for j in range(i, N):
ans = min(ans, gcd(A[i], A[j]))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
# A内の整数値を用いて作られる最小の整数を求めよ、という問題
def gcd(a, b):
"""
自然数a, b の最大公約数を求める
"""
if b == 0:
return a
else:
return gcd(b, a % b)
ans = gcd(A[0], A[1])
for i in range(1, N):
ans = min(ans, gcd(ans, A[i]))
print(ans)
|
p03127
|
def gcd(a, b):
lower = min(a, b)
bigger = max(a, b)
for i in range(lower, 0, -1):
if a%i==0 and b%i==0:
return i
def solve():
N = int(eval(input()))
A = [int(x) for x in input().split(" ")]
d = 10**9
for i in range(1, N):
d = min(gcd(A[0], A[i]), d)
print(d)
if __name__ == "__main__":
solve()
|
def gcd(a, b):
""" 最大公約数。aはbより大きいこと """
if b == 0:
return a
else:
return gcd(b, a%b)
def solve():
N = int(eval(input()))
A = [int(x) for x in input().split(" ")]
A.sort(reverse=True)
ans = A[0]
for i in range(1, N):
ans = gcd(ans, A[i])
print(ans)
if __name__ == "__main__":
solve()
|
p03127
|
n = int(eval(input()))
mon = list(map(int, input().split()))
g = min(mon)
div = []
for i in range(1, g + 1):
if (g % i == 0):
div.append(i)
div.append(g // i)
if (i * i > g):
break
div.sort(reverse=True)
for d in div:
mod = []
for m in mon:
mod.append(m % d)
if (list(set(mod)) == [0]):
print(d)
break
|
def gcd(x, y):
while(y):
x, y = y, x % y
return x
n = int(eval(input()))
mon = list(map(int, input().split()))
g = mon[0]
for i in range(1, n):
g = gcd(g, mon[i])
print(g)
|
p03127
|
N = int(eval(input()))
A = list(map(int, input().split()))
sort = sorted(A)
amari = []
while len(amari) != 1:
amari.clear()
if 0 in sort: sort.remove(0)
for item in sort:
if item%sort[0] not in amari:
amari.append(item%sort[0])
last_sort0 = sort[0]
sort = sorted(amari[:])
sort.append(last_sort0)
print((last_sort0-amari[0]))
|
N = int(eval(input()))
A = list(map(int, input().split()))
sort = sorted(A)
# amari = []
# while len(amari) != 1:
# amari.clear()
# if 0 in sort: sort.remove(0)
# for item in sort:
# if item%sort[0] not in amari:
# amari.append(item%sort[0])
# last_sort0 = sort[0]
# sort = sorted(amari[:])
# sort.append(last_sort0)
# print(last_sort0-amari[0])
while len(sort) != 1:
for i in range(1,len(sort)):
sort[i] = sort[i]%sort[0]
sort = [j for j in sorted(sort) if j != 0]
print((sort[0]))
|
p03127
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.