def gcd(a,b):
if (a%b==0):
return b
else:
return gcd(b,a%b)
N = int(input())
arr =list(map(int,input().split()))
arr.sort()
left_side = [0]*N
right_side = [0]*N
left_idx = 0
right_idx = 1
left_side[0] = arr[0]
right_side[-1] = arr[-right_idx]
for _ in range(N-1):
left_gcd = gcd(left_side[left_idx],arr[left_idx+1])
right_gcd = gcd(right_side[-right_idx],arr[-(right_idx+1)])
left_side[(left_idx+1)] = left_gcd
right_side[-(right_idx+1)] = right_gcd
left_idx += 1
right_idx += 1
result_gcd = -1
remove_data = -1
for i in range(N):
remove_value = arr[i]
if i == 0 or i == N-1:
if i == 0:
total_gcd = right_side[1]
else:
total_gcd = left_side[-2]
if remove_value%total_gcd:
if result_gcd < total_gcd:
result_gcd = total_gcd
remove_data = remove_value
else:
left_gcd = left_side[i-1]
right_gcd = right_side[i+1]
total_gcd = gcd(left_gcd,right_gcd)
if remove_value%total_gcd:
if result_gcd < total_gcd:
result_gcd = total_gcd
remove_data = remove_value
if result_gcd == -1:
print(result_gcd)
else:
print(result_gcd,remove_data)
'알고리즘 > 백준_복기_미완료' 카테고리의 다른 글
[BOJ/백준] 14595 동방 프로젝트(Large) (0) | 2021.05.05 |
---|---|
[BOJ/백준] 14570 나무 위의 구슬 (0) | 2021.05.05 |
[BOJ/백준] 13974 파일 합치기 2 (0) | 2021.05.05 |
[BOJ/백준] 13913 숨바꼭질 4 (0) | 2021.05.05 |
[BOJ/백준] 13460 구슬 탈출 2 (0) | 2021.05.05 |