Problem p03065 (python)

Fixed submission:
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    i = 1
    divset = set()
    while i * i <= a:
        if a % i == 0: divset |= {i, a//i}
        i += 1
    divset.remove(1)
    return divset

def is_prime(a):
    if a <= 3: 
        prime = [False, False, True, True]
        return prime[a]
    i = 2
    while i * i <= a:
        if a % i == 0: return False
        i += 1
    else: return True

N = int(input())
A = [None] * (N+1)
for i in reversed(range(N+1)):
    A[i] = int(input())

primes_bool = [True] * (N + 1)
primes = []
for p in range(2, N+1):
    if primes_bool[p]:
        primes.append(p)
        p_mult = p * 2
        while p_mult <= N:
            primes_bool[p_mult] = False
            p_mult += p

ans = []
used = set()
gcd_of_A = abs(A[N])
for a in A[:N]:
    if a != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > 1 and is_prime(d): 
        ans.append(d)
        used |= {d}

for p in primes:
    if A[0] % p == 0:
        for i in range(1, p):
            coefficient = 0
            index_a = i
            while index_a <= N:
                coefficient += A[index_a]
                coefficient %= p
                index_a += p-1
            if coefficient > 0: break
        else:
            if p not in used: ans.append(p)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    divset.remove(1)
    return divset

def is_prime(a):
    if a == 1: return False
    if a == 2 or a == 3: return True
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a % i == 0: return False
    else: return True

N = int(input())
A = [None] * (N+1)
for i in reversed(range(N+1)):
    A[i] = int(input())

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
used = {}
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a]
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: 
        ans.append(p)
        used |= {p}
        
gcd_of_A = abs(A[N])
for a in A[:N]:
    if a != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > 1 and is_prime(d) and d not in used: ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    divset.remove(1)
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [None] * (N+1)
for i in reversed(range(N+1)):
    A[i] = int(input())

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
        
gcd_of_A = abs(A[N])
for a in A:
    if A[N] != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > N and is_prime(d): ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
        
gcd_of_A = abs(A[N])
for a in A:
    if a != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > N and is_prime(d): ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
        
gcd_of_A = abs(A[N])
for a in A[:N]:
    if a != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > N and is_prime(d): ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    divset -= {1}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

gcd_of_A = A[N]
for a in A[:N]:
    if a != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
        
commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > N and is_prime(d): ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    divset -= {1}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

gcd_of_A = A[N]
for i in reversed(range(N)):
    if A[i] != 0:
        gcd_of_A = gcd(abs(A[i]), gcd_of_A)

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: 
        ans.append(p)
        
#if gcd_of_A > 1:
    #divisor_of_A = divisor(gcd_of_A)
    #for d in divisor_of_A:
        #if d > N:
            #if is_prime(d):
                #ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    divset -= {1}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

gcd_of_A = A[N]
for i in reversed(range(N)):
    if A[i] != 0:
        gcd_of_A = gcd(abs(A[i]), gcd_of_A)

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: 
        ans.append(p)
        
if gcd_of_A > 1:
    divisor_of_A = divisor(gcd_of_A)
    for d in divisor_of_A:
        if d > N:
            if is_prime(d):
                ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    divset -= {1}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

gcd_of_A = A[N]
for i in reversed(range(N)):
    if A[N] != 0:
        gcd_of_A = gcd(abs(A[i]), gcd_of_A)

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: 
        ans.append(p)
        
if gcd_of_A > 1:
    divisor_of_A = divisor(gcd_of_A)
    for d in divisor_of_A:
        if d > N:
            if is_prime(d):
                ans.append(d)

ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

gcd_of_A = A[N]
for i in reversed(range(N)):
    if A[N] != 0:
        gcd_of_A = gcd(abs(A[i]), gcd_of_A)

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a] % p
            coefficient %= p
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
used = set(ans)

divisor_of_An = divisor(A[N])
for div in divisor_of_An:
    if div > N:
        if is_prime(div):
            if gcd_of_A % div == 0 and div not in used: ans.append(div)
ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a]
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
used = set(ans)

divisor_of_An = divisor(A[N])
for div in divisor_of_An:
    if div > 1:
        if is_prime(div):
            for a in A:
                if a % div > 0: break
            else:
                if div not in used: 
                    ans.append(div)
ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    for i in range(p-1):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a]
            index_a += p-1
        if coefficient % p > 0: break
    else: ans.append(p)
used = set(ans)

divisor_of_An = divisor(A[N])
for div in divisor_of_An:
    if div > 1:
        if is_prime(div):
            for a in A:
                if a % div > 0: break
            else:
                if div not in used: 
                    ans.append(div)
ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    sum = A[0] % p
    for i in range(1, p):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a]
            index_a += p-1
        sum += coefficient % p
        sum %= p
    if sum % p == 0: ans.append(p)

used = set(ans)

divisor_of_An = divisor(A[N])
for div in divisor_of_An:
    if div > 1:
        if is_prime(div):
            for a in A:
                if a % div > 0: break
            else:
                if div not in used: 
                    ans.append(div)
ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = [int(input()) for n in range(N+1)]

primes = [int(i) for i in range(2, N+1)]
primes = set(primes)
for i in range(2, N+1):
    temp = set()
    for p in primes:
        if p % i > 0 or p == i: temp |= {p}
    primes = temp

ans = []
for p in primes:
    sum = A[0] % p
    for i in range(1, p):
        coefficient = 0
        index_a = i
        while index_a <= N:
            coefficient += A[index_a]
            index_a += p-1
        sum += coefficient % p
        sum %= p
    if sum % p == 0: ans.append(p)

divisor_of_An = divisor(A[N])
for div in divisor_of_An:
    if div > 1:
        if is_prime(div):
            for a in A:
                if a % div > 0: break
            else:
                if div not in ans: ans.append(div)
ans.sort()
for a in ans: print(a)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a != i and a % i == 0: return False
    else: return True

N = int(input())
A = []
sum = 0
for n in range(N+1):
    a = abs(int(input()))
    if a > 0: 
        A.append(a)
        sum += a % 2
        sum %= 2
div_by_two = False
if sum  == 0: div_by_two = True

gcd_of_A = A[0]
for a in A[1:]:
    gcd_of_A = gcd(gcd_of_A, a)

sum = 0
if not div_by_two:
    for a in A: 
        sum += (a // gcd_of_A) % 2
        sum %= 2
if sum == 0: div_by_two = True

commondiv = divisor(gcd_of_A)
primes = []
for div in commondiv:
    if div > 1 and is_prime(div): primes.append(div)
primes.sort()
if primes[0] != 2 and div_by_two: print(2)
for p in primes: print(p)

Buggy submission (verdict: Runtime Error):
from math import sqrt

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    lim = int(sqrt(a))
    divset = set()
    for i in range(1, lim + 1):
        if a % i == 0:
            divset |= {i, a//i}
    return divset

def is_prime(a):
    lim = int(sqrt(a))
    for i in range(2, lim + 1):
        if a % i == 0: return False
    else: return True

N = int(input())
A = [abs(int(input())) for n in range(N+1)]

gcd_of_A = A[0]
for a in A[1:]:
    gcd_of_A = gcd(gcd_of_A, a)

if gcd_of_A > 1:
    commondiv = divisor(gcd_of_A)
    while True:
        A[0] //= gcd_of_A
        newgcd = A[0]
        for a in A[1:]:
            a //= gcd_of_A
            newgcd = gcd(newgcd, a)
        if newgcd == 1: break
        else:
            newdivisor = divisor(newgcd)
            commondiv |= newdivisor
            gcd_of_A = newgcd
    
    primes = []
    for div in commondiv:
        if div > 1 and is_prime(div): primes.append(div)
    primes.sort()
    for p in primes: print(p)