Problem p03061 (python)

Fixed submission:
def gcdf(a):
    a.sort()
#    print("a2:",a)
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
#    print("a2:",a)
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

#n=8
#a=[746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#ans=[19]
#n=2
#a=[1000000000, 1000000000]
#n=5
#a=[15, 18, 24, 36, 81]
#n=3
#a=[7, 6, 8]
n=int(input())
a=[]
for i in map(int,input().split()):
    a.append(i)
if n==2:
    print(max(a))
elif n<2**10:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
else:
    m=int(n**(1/2))
    ns=int(n/m)
    rgcd=[]
    for mi in range(m):
        ms=ns*mi
        if mi==m-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
        gcdm=gcdf(am)
        rgcd.append(gcdm)
    gcdv=0

    for mi in range(m):
        rgcd1=list(rgcd)
        del rgcd1[mi]
        gcdrg1=gcdf(rgcd1)
        ms=ns*mi
        if mi==m-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
#        print(mi,gcdf(am),len(am),gcdf(rgcd1))
        for i in range(len(am)):
            acpy=list(am)
#            del acpy[i]
#            acpy.append(gcdrg1)
            acpy[i]=gcdrg1
            gcdx=gcdf(acpy)
            if gcdx>gcdv:
                gcdv=gcdx
    print(gcdv)

Buggy submission (verdict: Runtime Error):
# ==================== gcd   最大公約数
#from fractions import gcd
from math import gcd

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

l=[0]*(n+1)
r=[0]*(n+1)

for i in range(n):
    l[i+1]=gcd(l[i],a[i])
    r[n-i-1]=gcd(r[n-i],a[n-i-1])

mimax=1
for i in range(n):
    mi=gcd(l[i],r[i+1])
    mimax=max(mi,mimax)
   
print(mimax)

Buggy submission (verdict: Runtime Error):
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
#    print("a2:",a)
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

#n=8
#a=[746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#ans=[19]
#n=2
#a=[1000000000, 1000000000]
#n=5
#a=[15, 18, 24, 36, 81]
#n=3
#a=[7, 6, 8]
n=int(input())
a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n<2**10:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
else:
    m=2**9
    ns=int(n/m)
    rgcd=[]
    for mi in range(m):
        ms=ns*mi
        if mi==n-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
        gcdm=gcdf(am)
        rgcd.append(gcdm)

    gcdv=0

    for mi in range(m):
        rgcd1=rgcd.copy()
        del rgcd1[mi]
        ms=ns*mi
        if mi==n-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
        for i in range(len(am)):
            acpy=am.copy()
            del acpy[i]
            acpy=acpy+rgcd1
            gcdx=gcdf(acpy)
            if gcdx>gcdv:
                gcdv=gcdx

#    print(gcdv,a1)
    print(gcdv)

Buggy submission (verdict: Runtime Error):
def gcdf(a,n,a0):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
#    print("a2:",a)
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a,n,a0) 

#n=8
#a=[746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#ans=[19]
#n=2
#a=[1000000000, 1000000000]
#n=5
#a=[15, 18, 24, 36, 81]
#n=3
#a=[7, 6, 8]
n=int(input())
a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n<=2**10:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        a0=acpy[0]
        gcdx=gcdf(acpy,n-1,a0)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
else:
    a.sort()
    ns=int(n/4)
    a1=a[0:ns]
    a2=a[ns:ns*2]
    a3=a[ns*2:ns*3]
    a4=a[ns*3:n]
#    print(a1)
#    print(a2)
#    print(a3)
#    print(a4)
    gcdv=0
    a10=a1[0]
    a20=a2[0]
    a30=a3[0]
    a40=a4[0]
    gcd1=gcdf(a1,len(a1),a10)
    gcd2=gcdf(a2,len(a2),a20)
    gcd3=gcdf(a3,len(a3),a30)
    gcd4=gcdf(a4,len(a4),a40)
    for i in range(ns):
#        acpy=list(a1)
        acpy=a1.copy()
        acpy.append(gcd2)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a10)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a1)
    for i in range(ns):
#        acpy=list(a2)
        acpy=a2.copy()
        acpy.append(gcd1)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a20)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a2)
    for i in range(ns):
#        acpy=list(a3)
        acpy=a3.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd4)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a30)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a3)
    for i in range(ns):
#        acpy=list(a4)
        acpy=a4.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd3)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a40)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a4)
    print(gcdv)

Buggy submission (verdict: Runtime Error):
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n>=16:
    a.sort()
    ns=int(n/4)
    a1=a[0:ns]
    a2=a[ns:ns*2]
    a3=a[ns*2:ns*3]
    a4=a[ns*3:n]
    print(a1)
    print(a2)
    print(a3)
    print(a4)
    gcdv=0
    gcd1=gcdf(a1,len(a1),gcdv)
    gcd2=gcdf(a2,len(a2),gcdv)
    gcd3=gcdf(a3,len(a3),gcdv)
    gcd4=gcdf(a4,len(a4),gcdv)
    for i in range(ns):
#        acpy=list(a1)
        acpy=a1.copy()
        acpy.append(gcd2)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a1)
    for i in range(ns):
#        acpy=list(a2)
        acpy=a2.copy()
        acpy.append(gcd1)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a2)
    for i in range(ns):
#        acpy=list(a3)
        acpy=a3.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd4)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a3)
    for i in range(ns):
#        acpy=list(a4)
        acpy=a4.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd3)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a4)
    print(gcdv)
    
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Buggy submission (verdict: Runtime Error):
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n<-16:
    ns=int(n/8)
    a1=[0:ns]
    a2=[ns:ns*2]
    a3=[ns*2:ns*3]
    a4=[ns*3:n]
    gcdv=0
    gcd1=gcdf(a1,len(a1),gcdv)
    gcd2=gcdf(a2,len(a2),gcdv)
    gcd3=gcdf(a3,len(a3),gcdv)
    gcd4=gcdf(a4,len(a4),gcdv)
    
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import functools
#import math

def gcdf(a,n):
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(1,n):
            ra=a[i]%a0
#            print(ra,a0,i,ramin)
            if ramin>ra and ra!=0:
                ramin=ra
        a0=ramin
    return ramin


#n=2
#a=[1000000000, 1000000000]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)
#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
#    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
#        gcdx=gcdf(acpy,n-1)
#        gcdx=gcd(acpy)
#        gcdx=functools.reduce(gcd,acpy)
        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Buggy submission (verdict: Runtime Error):
#from fractions import gcd
import functools
import math

n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)
#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)
#print(a)
if n==2:
    print(max(a))
else:
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcd(acpy)
        if gcdx>gcd:
            gcd=gcdx
    print(gcd)