Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):

import sys

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

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


if n==2:
  print(max(a))
  sys.exit(0)


tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])

for i in range(2,n):
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
      
print(tmp_used)





import sys
#math
def gcd(a, b): 
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


if n==2:
  print(max(a))
  sys.exit(0)

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd=ret(a)
else:
  tmp_unused = gcd3(a[:10])
  tmp_used = ret(a[:10])
  for i in range(10,n-1):
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)





import sys
#math
def gcd(a, b): 
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))

if n==1:
  print(a[0])
  sys.exit(0)

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd=ret(a)
else:
  tmp_unused = gcd3(a[:10])
  print(a[:10])
  tmp_used = ret(a[:10])
  for i in range(10,n-1):
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)





import sys

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

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


if n==2:
  print(max(a))
  sys.exit(0)

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<=10:
  maxgcd = ret(a)
else:
  tmp_unused = gcd3(a[:10])
  tmp_used = ret(a[:10])
  #print(a[:10])
  for i in range(10,n):
    #print(a[i])
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
    #print("tmp", tmp_unused, tmp_used)
  maxgcd=tmp_used
      
print(maxgcd)





import sys
#math
def gcd(a, b): 
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
n = len(a)

if n==1:
  print(a[0])
  sys.exit(0)

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd=ret(a)
else:
  tmp_unused = gcd3(a[:10])
  print(a[:10])
  tmp_used = ret(a[:10])
  for i in range(10,n-1):
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)





import sys

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

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


if n==2:
  print(max(a))
  sys.exit(0)

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd = ret(a)
else:
  tmp_unused = gcd3(a[:10])
  tmp_used = ret(a[:10])
  #print(a[:10])
  for i in range(10,n):
    #print(a[i])
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)





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

def gcd3(lis): (3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())

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

maxgcd = 0
for i in range(n):
  nums = [a[j] for j in range(n) if j!=i]
  #print(nums)
  tmp = gcd3(nums)
  if maxgcd<tmp:
    maxgcd=tmp
    
print(maxgcd)





import sys

def gcd(a, b): 
  while b:
    a, b = b, a % b
  return int(a)
    
n = int(input())
a = list(map(int, input().split()))


if n==2:
  print(max(a))
  sys.exit(0)
elif n==3:
  lis = [gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])]
  print(max(lis))
  sys.exit(0)


tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])


for i in range(2,n):
  #print(a[i])
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
  
  
print(tmp_used)




Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Time Limit Exceeded

Accepted