Problem:


Score : 800 points

Problem Statement

You are given a polynomial of degree N with integer coefficients: f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0. Find all prime numbers p that divide f(x) for every integer x.

Constraints

0 \leq N \leq 10^4

|a_i| \leq 10^9(0\leq i\leq N)

a_N \neq 0

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_N
:
a_0

Output

Print all prime numbers p that divide f(x) for every integer x, in ascending order.

Sample Input 1

2
7
-7
14

Sample Output 1

2
7

2 and 7 divide, for example, f(1)=14 and f(2)=28.

Sample Input 2

3
1
4
1
5

Sample Output 2

There may be no integers that satisfy the condition.

Sample Input 3

0
998244353

Sample Output 3

998244353



Sample input:
2
7
-7
14


Sample output:
2
7

Submission status: Accepted

Solution code:
def prime_fact(n: int)->list:
    '''n の素因数を返す
    '''
    if n < 2:
        return []

    d = 2
    res = []
    while n > 1 and d * d <= n:
        if n % d == 0:
            res.append(d)
        while n % d == 0:
            n //= d
        d += 1

    if n > 1:
        # n が素数
        res.append(n)

    return res


def gen_primes(n: int)->int:
    '''n まで(n 含む)の素数を返します。
    '''
    if n < 2:
        return []
    primes = [2]

    if n < 3:
        return primes
    primes.append(3)

    def is_prime(n: int)->bool:
        for p in primes:
            if n % p == 0:
                return False
        return True

    # 2,3 以降の素数は 6k+1 あるいは 6k-1
    # の形をしていることを利用して列挙する。
    for k in range((N+1)//6):
        k += 1

        if is_prime(6*k-1):
            primes.append(6*k-1)

        if is_prime(6*k+1):
            primes.append(6*k+1)

    return primes


def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a
    return a if b == 0 else gcd(b, a % b)


def gcd_list(A: list)->int:
    if len(A) == 0:
        return 0
    if len(A) == 1:
        return A[0]

    g = abs(A[0])
    for a in A[1:]:
        g = gcd(g, abs(a))
    return g


def polynominal_divisors(N: int, A: list)->list:
    # primes = prime_fact(abs(A[-1]))
    A.reverse()
    # 候補となる素数は、N 以下の素数あるいは、aN の素因数

    def check(p: int)->bool:
        '''素数 p が任意の整数 x について f(x) を割り切れるかを
        check する。具体的には、

        - a0
        - a1 + ap + a{2p-1} + ...
        - a2 + a{p+1} + a{2p} + ...
        ...
        - a{p-1} + a{2p-2} + ...
        という項が p で割り切れるかを検査する。
        '''
        if A[0] % p != 0:
            return False

        for i in range(1, min(N, p)):
            # ai + a{i+p-1} + ... を求めて
            # p で割り切れるか検査する。
            # print('p={}'.format(p))
            b = 0
            while i <= N:
                # print('i={}'.format(i))
                b = (b + A[i]) % p
                i += p-1
            if b != 0:
                return False
        return True

    primes = set(gen_primes(N) + prime_fact(gcd_list(A)))
    res = [p for p in primes if check(p)]
    res.sort()

    return res


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N+1)]

    ans = polynominal_divisors(N, A)
    for a in ans:
        print(a)

Submission status: Accepted

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

def eratosthenes(n):
    if n < 2:
        return []
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime

N = int(input())
A = [int(input()) for i in range(N+1)]
g = abs(A[0])
for a in A:
     g = gcd(g,abs(a))
d = prime_decomposition(g)
ans = [p for p in d]

prime = eratosthenes(N+1)
A.reverse()
for p in prime:
    if A[0]%p != 0:
        continue
    for n in range(1,p):
        s = 0
        for k in range(int((N-n)/(p-1))+1):
            s += A[n+k*(p-1)]
            s %= p
        if s != 0:
            break
    if s == 0:
        ans.append(p)

ans = list(set(ans))
ans.sort()

for p in ans:
    print(p)

Submission status: Accepted

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

def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

def eratosthenes(n):
    if n < 2:
        return []
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime

def ok(p):
    if A[0]%p != 0:
        return False
    B = [A[i]%p for i in range(1,N+1)]
    mod = [0]*(p-1)
    for i in range(N):
        mod[i%(p-1)] += B[i]
        mod[i%(p-1)] %= p
    return sum(mod)==0

N = int(input())
A = [int(input()) for i in range(N+1)][::-1]
g = abs(A[0])
for a in A:
     g = gcd(g,abs(a))
d = prime_decomposition(g)
ans = [p for p in d]

prime = eratosthenes(N+1)

for p in prime:
    if ok(p):
        ans.append(p)

ans = list(set(ans))
ans.sort()

for p in ans:
    print(p)

Submission status: Accepted

Solution code:
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(x%y,y)
N=int(input())
a=[int(input()) for i in range(N+1)][::-1]
#N=10000
#a=[i+1 for i in range(N+1)]
g=abs(a[0])
for i in range(1,N+1):
    g=gcd(g,abs(a[i]))
def check(P):
    b=[a[i]%P for i in range(1,N+1)]
    if a[0]%P!=0:
        return False
    if N<P:
        for i in b:
            if i!=0:
                return False
        return True
    else:
        c=[0 for i in range(P-1)]
        for i in range(N):
            c[i%(P-1)]+=b[i]
            c[i%(P-1)]%=P
        for i in c:
            if i!=0:
                return False
        return True
Plist=set()
X=[1 for i in range(max(N+1,3))]
X[0]=0;X[1]=0
i=2
while(i*i<=N):
    for j in range(i,N+1,i):
        if i==j:
            if X[i]==0:
                break
        else:
            X[j]=0
    i+=1
i=2
tmp=g
while(i*i<=g):
    if tmp%i==0:
        Plist.add(i)
        while(1):
            if tmp%i==0:
                tmp=tmp//i
            else:
                break
    i+=1
if tmp>1:
    Plist.add(tmp)
for j in range(N+1):
    if X[j]==1:
        Plist.add(j)
Plist=sorted(list(Plist))
for p in Plist:
    if check(p):
        print(p)

Submission status: Accepted

Solution code:
def gcd(a, b):
	while a > 0 and b > 0:
		a, b = b, a % b
	return a + b

def st(a, b):
	if b == 0:
		return 1
	if b % 2 == 0:
		q = st(a, b // 2)
		return q * q
	return a * st(a, b - 1)

n = int(input())
a = []
for i in range(n + 1):
	x = int(input())
	a.append(x)
ans = 0
massiv = [1, 2, 3, 5, 7, 11, 13, 17, 19, 21, 23, 9, 16]
for x in massiv:
	tmp = 0
	r = st(x, n)
	for i in range(0, n + 1):
		tmp += a[i] * r
		r //= x
	ans = gcd(ans, abs(tmp))
v = []
j = 2
while j * j <= ans:
	if ans % j == 0:
		ans //= j
		v.append(j)
	else:
		j += 1
if ans != 1:
	v.append(ans)
v.sort()
for i in range(len(v)):
	if i == 0 or v[i] != v[i - 1]:
		print(v[i])

Submission status: Accepted

Solution code:
from functools import reduce
import random
MOD = 59490679579998635868564022242503445659680322440679327938309703916140405638383434744833220555452130558140772894046169700747186409941317550665821619479140098743288335106272856533978719769677794737287419461899922456614256826709727133515885581878614846298251428096512495590545989536239739285290509870860732435109794045491640561011775744617218426011793283330497878491137999673760740717904979730106994180691956740996319139767941335979146924614249205862051182094081815447356600355657858936442589201739350474320966093143098768914226528498860747050474426418211313776073365498029087492308102876323562641651940555529817223923967479711293692697592800750806084802623966596666156361791014935954720420383555300213829134029560826306201326905674141090667002959274513478562033467485802590354539887133866434256562999666615074220857502563011098759348850149774083443643246907501430076141377431759984926248272553982527014011245310690986644461251576837779050124866641531488351016070300247918750613207952783437248236577750579092103591540592540838395240861443615842939673889972504776455114767522430347610500271801944701491874649306605557851914677316523034726044356368337787113190245601235705959816327016988315321850324065292964680148884818699916224411245926491625245571963741062587277736372090007125908660590314049976206281064703285728879581199596401313352724403492043120507597057004633720111008838673185885941472392623805512709896864520875740497617898566981218781313900004406341154884180472153171064617953661517880143988867189622824081729539392205701820144922307223627345876707465251206005262622236311161449785941834002795854996108322186230425179217618301526151712928790928933798369678844576216735378555233905935973195721247604933753363412045618703247367192610615234835041956551569232557323060407648325565048712478527583315981204846341857095134567470182330491262285172727037299211391244340592936174221176781260586188162350081192408213470101717320475998863222409777310443027421196981193126541663212124245716187453863438039402316877152286468198891603632606578778749292403571792687832081974134637014026451921536576338243322267400651083805535119025415817887075652758045539565968044552126338330231434466204888993650859153585380124240540573308417330478048240203241631072371322849430883727355239704116556046700749530006852187064160849175332758172150251213637470549781080491037088372092203085237973008861896576796238915011886636658033019385943299986285181723378096425117379056207797455963451889971988904466449319007760192467211209692128894691704353648198130409333996534250878389064152054828983825841234644875996912485916827004219887033833599723481903489316488764021700996686817244736947119285629049355809027206179193628292018441744552168286541735687924729198455883895791600170372255284216915442808139396541702893732917062958054499525549626455191658842064247047426187897146172971001949767308335268505414284088528125611263685734457560292833389995980698745893243832547007166243476192958601735336260255598581701267151224204461879782815468518040925292817115377696676461775120750971210951527384637825092221708015393564320979357698186262039029460777050248162599194429941464248920952161182024344007059684970270762248243899640259750891406957836740989312390963091260380990901672119736141666856448171380781556117025832312710039041398538035351795267732240730608951176127282191528457681241590895740457571038936173983449289126574141189374690274057472401359482497502067814596008557725079835212621242944853319496441084441343866446380876967613370281793088540430288658573281302876742323336651987699532240686371751448290351615451932054274752105688318766958111191822471878078268490672607804265064578569581247796205593441336042254502454646980009177290888726099355974892680373341371214123450598691915802122913613669446370194221846225597401405625536693874723700374068542217340621938985167525416725638580266200550048001242788847319217369432802469735271132107428204697172144851088692772696511622350096452418244968500432645305761138012204888798724453956720733374364721511323104353496583927094760495687785031050687852300161433757934364774351673531859394855389527851678630166084819717354779333605871648837631164630550613112327670353108353791304451834904017538583880634608113426156225757314283269948216017294095002859515842577481167417167637534527111130468710

def gcd(a, b):
    b = abs(b)
    while b != 0:
        r = a%b
        a,b = b,r
    return a
def gcd_mult(numbers):
    return reduce(gcd, numbers)

N = int(input())
A = [int(input()) for _ in range(N+1)][::-1]
g = gcd_mult(A)

A = [a//g for a in A]

def f(n):
    ret = A[N]
    for i in range(N-1, -1, -1):
        ret = (ret * n + A[i]) % MOD
    return ret

ans = MOD
for _ in range(20):
    k = random.randrange(10**10)
    ans = gcd(ans, f(k))

def primeFactor(N):
    i = 2
    ret = {}
    n = N
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    d = 2
    sq = int(n ** (1/2))
    while i <= sq:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        if k > 0:
            sq = int(n**(1/2))
        if i == 2:
            i = 3
        elif i == 3:
            i = 5
        elif d == 2:
            i += 2
            d = 4
        else:
            i += 4
            d = 2
        
    if n > 1:
        ret[n] = 1
    return ret
ANS = []
for i in primeFactor(ans*g):
    ANS.append(i)

ANS = sorted(ANS)
for ans in ANS:
    print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
	while a > 0 and b > 0:
		a, b = b, a % b
	return a + b

def st(a, b):
	if b == 0:
		return 1
	if b % 2 == 0:
		q = st(a, b // 2)
		return q * q
	return a * st(a, b - 1)

n = int(input())
a = []
for i in range(n + 1):
	x = int(input())
	a.append(x)
ans = 0
for x in range(1, 18):
	tmp = 0
	r = st(x, n)
	for i in range(0, n + 1):
		tmp += a[i] * r
		r //= x
	ans = gcd(ans, abs(tmp))
v = []
j = 2
while j * j <= ans:
	if ans % j == 0:
		ans //= j
		v.append(j)
	else:
		j += 1
if ans != 1:
	v.append(ans)
v.sort()
for i in range(len(v)):
	if i == 0 or v[i] != v[i - 1]:
		print(v[i])

Submission status: Accepted

Solution code:
from functools import reduce
import random
import time
MOD = 59490679579998635868564022242503445659680322440679327938309703916140405638383434744833220555452130558140772894046169700747186409941317550665821619479140098743288335106272856533978719769677794737287419461899922456614256826709727133515885581878614846298251428096512495590545989536239739285290509870860732435109794045491640561011775744617218426011793283330497878491137999673760740717904979730106994180691956740996319139767941335979146924614249205862051182094081815447356600355657858936442589201739350474320966093143098768914226528498860747050474426418211313776073365498029087492308102876323562641651940555529817223923967479711293692697592800750806084802623966596666156361791014935954720420383555300213829134029560826306201326905674141090667002959274513478562033467485802590354539887133866434256562999666615074220857502563011098759348850149774083443643246907501430076141377431759984926248272553982527014011245310690986644461251576837779050124866641531488351016070300247918750613207952783437248236577750579092103591540592540838395240861443615842939673889972504776455114767522430347610500271801944701491874649306605557851914677316523034726044356368337787113190245601235705959816327016988315321850324065292964680148884818699916224411245926491625245571963741062587277736372090007125908660590314049976206281064703285728879581199596401313352724403492043120507597057004633720111008838673185885941472392623805512709896864520875740497617898566981218781313900004406341154884180472153171064617953661517880143988867189622824081729539392205701820144922307223627345876707465251206005262622236311161449785941834002795854996108322186230425179217618301526151712928790928933798369678844576216735378555233905935973195721247604933753363412045618703247367192610615234835041956551569232557323060407648325565048712478527583315981204846341857095134567470182330491262285172727037299211391244340592936174221176781260586188162350081192408213470101717320475998863222409777310443027421196981193126541663212124245716187453863438039402316877152286468198891603632606578778749292403571792687832081974134637014026451921536576338243322267400651083805535119025415817887075652758045539565968044552126338330231434466204888993650859153585380124240540573308417330478048240203241631072371322849430883727355239704116556046700749530006852187064160849175332758172150251213637470549781080491037088372092203085237973008861896576796238915011886636658033019385943299986285181723378096425117379056207797455963451889971988904466449319007760192467211209692128894691704353648198130409333996534250878389064152054828983825841234644875996912485916827004219887033833599723481903489316488764021700996686817244736947119285629049355809027206179193628292018441744552168286541735687924729198455883895791600170372255284216915442808139396541702893732917062958054499525549626455191658842064247047426187897146172971001949767308335268505414284088528125611263685734457560292833389995980698745893243832547007166243476192958601735336260255598581701267151224204461879782815468518040925292817115377696676461775120750971210951527384637825092221708015393564320979357698186262039029460777050248162599194429941464248920952161182024344007059684970270762248243899640259750891406957836740989312390963091260380990901672119736141666856448171380781556117025832312710039041398538035351795267732240730608951176127282191528457681241590895740457571038936173983449289126574141189374690274057472401359482497502067814596008557725079835212621242944853319496441084441343866446380876967613370281793088540430288658573281302876742323336651987699532240686371751448290351615451932054274752105688318766958111191822471878078268490672607804265064578569581247796205593441336042254502454646980009177290888726099355974892680373341371214123450598691915802122913613669446370194221846225597401405625536693874723700374068542217340621938985167525416725638580266200550048001242788847319217369432802469735271132107428204697172144851088692772696511622350096452418244968500432645305761138012204888798724453956720733374364721511323104353496583927094760495687785031050687852300161433757934364774351673531859394855389527851678630166084819717354779333605871648837631164630550613112327670353108353791304451834904017538583880634608113426156225757314283269948216017294095002859515842577481167417167637534527111130468710
sTime = time.time()

def gcd(a, b):
    b = abs(b)
    while b != 0:
        r = a%b
        a,b = b,r
    return a
def gcd_mult(numbers):
    return reduce(gcd, numbers)

N = int(input())
A = [int(input()) for _ in range(N+1)][::-1]
g = gcd_mult(A)

A = [a//g for a in A]

def f(n):
    ret = A[N]
    for i in range(N-1, -1, -1):
        ret = (ret * n + A[i]) % MOD
    return ret

ans = MOD
while time.time()-sTime < 1.5:
    k = random.randrange(10**10)
    ans = gcd(ans, f(k))

def primeFactor(N):
    i = 2
    ret = {}
    n = N
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    d = 2
    sq = int(n ** (1/2))
    while i <= sq:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        if k > 0:
            sq = int(n**(1/2))
        if i == 2:
            i = 3
        elif i == 3:
            i = 5
        elif d == 2:
            i += 2
            d = 4
        else:
            i += 4
            d = 2
        
    if n > 1:
        ret[n] = 1
    return ret
ANS = []
for i in primeFactor(ans*g):
    ANS.append(i)

ANS = sorted(ANS)
for ans in ANS:
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys, collections, bisect, math, itertools
from fractions import gcd 
#input = sys.stdin.readline #文字列入力のときは注意

m = int(input())
#s = input()
#a = [int(i) for i in input().split()]
a = [int(input()) for j in range(m+1)] # 縦「n」行

beki = 0
while a[-1] == 0:
    a.pop()
    beki+=1
if m != len(a)-1:
    m = len(a)
    a.append(0)


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
allprimes = get_sieve_of_eratosthenes(10010)

primes=[]
def get_sieve_of_eratosthenes2():
    prime = []
    data = [i + 1 for i in range(1, 35000)]
    c=abs(a[m])
    while True:
        p = data[0]
        if 10**9 <= p*p:
            return prime + data
        if c%p==0: primes.append(p)
        prime.append(p)
        data = [e for e in data if e % p != 0]

primes2=[]
def get_sieve_of_eratosthenes3():
    prime = []
    data = [i + 1 for i in range(1, 35000)]
    c=abs(a[0])
    while True:
        p = data[0]
        if 10**9 <= p*p:
            return prime + data
        if c%p==0: primes2.append(p)
        prime.append(p)
        data = [e for e in data if e % p != 0]


get_sieve_of_eratosthenes2()
get_sieve_of_eratosthenes3()
if len(primes) == 0 and abs(a[m]) != 1:
    primes.append(abs(a[m]))
if a[m]==0:
    primes = allprimes
if len(primes2) == 0 and abs(a[0]) != 1 and abs(a[0]) not in primes:
    primes2.append(abs(a[0]))
n=m


primes = sorted(list(set(primes + primes2)))
#print(a)
#print(primes)
for p in primes:
    if p > 10**4+5:
        if sum([i%p for i in a]) == 0:
            print(p)
        continue
    coeff = list(reversed(a))
    while len(coeff) > p:
#        print(coeff,p)
        t=coeff.pop()
        coeff[-p+1]+=t
            
#    print(coeff)
    if sum([i%p for i in coeff]) == 0:
        print(p)

Submission status: Runtime Error

Solution code:
from functools import reduce

N=int(input())

def factorize(n):
    out=[]
    i = 2
    while 1:
        if n%i==0:
            out.append(i)
            n //= i
        else:
            i += 1
        if n == 1:break
        if i > int(n**.5+3):
            out.append(n)
            break
    
    return out
  
def gcd(a,b):
  if b==0:return a
  return gcd(b,a%b)

if N==0:
  ans = factorize(int(input()))
  print(*ans)
  exit()
  
a = [int(input()) for _ in range(N+1)]
  
g = reduce(gcd,a)
ans = factorize(g)
print(*ans)

Submission status: Runtime Error

Solution code:
#とりあえずRE削除目標
from random import randint, choice
import math
#from math import gcd
from fractions import gcd
def is_prime(x):#https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = int(input())
a=[]
for _ in range(n+1):
    a.append(int(input()))
a.reverse()

prm0 = []
prm02 = []
a0 = a[0]

sq = int(a0**(1/2))+3

for i in range(2,sq):
    if a0%i==0:
        prm0.append(i)
        prm02.append(a0//i)
pr_ = prm0+prm02
if a0:
    pr_.append(a0)
pr = []
for p in pr_:
    if is_prime(p):
        pr.append(p)
def f(x,p):
    res = 0
    for i in range(n+1):
        res += pow(x,i,p)*a[i]
    return res
ans_l = []
pr2 = {p for p in pr}
ax = 0
for i in range(50):
    t = randint(5,1000)
    pi=choice(pr)
    if f(t,pi):
        ax = f(t,pi)
        break
for _ in range(50):
    ans = ax
    rn = randint(1,10**9)
    ans = gcd(ans,f(rn,ax))
    for p in pr:
        if ans%p and p in pr2:
            pr2.delete(p)

for p in pr2:
    print(p)

Submission status: Runtime Error

Solution code:
#とりあえずRE削除目標
from random import randint
import math
#from math import gcd
from fractions import gcd
def is_prime(x):#https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = int(input())
a=[]
for _ in range(n+1):
    a.append(int(input()))
a.reverse()

prm0 = []
prm02 = []
a0 = a[0]

sq = int(a0**(1/2))+3

for i in range(2,sq):
    if a0%i==0:
        prm0.append(i)
        prm02.append(a0//i)
pr_ = prm0+prm02
if a0:
    pr_.append(a0)
pr = []
for p in pr_:
    if is_prime(p):
        pr.append(p)
def f(x,p):
    res = 0
    for i in range(n+1):
        res += pow(x,i,p)*a[i]
    return res
ans_l = []
pr2 = {p for p in pr}
ax = 0
for i in range(50):
    t = randint(5,1000)
    if f(t,p):
        ax = f(t,p)
        break
for _ in range(50):
    ans = ax
    rn = randint(1,10**9)
    ans = gcd(ans,f(rn,ax))
    for p in pr:
        if ans%p and p in pr2:
            pr2.remove(p)

for p in pr2:
    print(p)

Submission status: Runtime Error

Solution code:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

sosuu=[2];A=10000
for L in range(3,A):
    chk=True
    for L2 in sosuu:
        if L%L2 == 0:chk=False
    if chk==True:sosuu.append(L)
S=set(sosuu)



n=int(input())
A=[0]*(n+1)
g=0
for i in range(n+1):
  A[i]=int(input())
P=[]
PP=factorization(A[0])
for i in range(len(PP)):
  P.append(PP[i][0])
if P==[1]:
  P=[]
P=set(P)
P=S|P
P=list(P)
P.sort()
for i in range(len(P)):
  p=P[i]
  B=A[0:n+2]
  b=0
  for j in range(n+1):
    if p+j<n+2:
      B[j+p-1]=(B[j+p-1]+B[j])%p
    else:
      if A[j]%p!=0:
        b=1
        break
  if b==0:
    print(p)

Submission status: Runtime Error

Solution code:
import copy
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n=int(input())
A=[0]*(n+1)
for i in range(n+1):
  A[i]=int(input())
P=[]
PP=factorization(A[-1])
for i in range(len(PP)):
  P.append(PP[i][0])
print(P)
for i in range(len(P)):
  p=P[i]
  B=copy.copy(A)
  for j in range(n+1):
    if p+j<n+2:
      B[j+p-1]=(B[j+p-1]+B[j])%p
      print(B)
    else:
      print(B)
      if A[j]%p!=0:
        break
  print(p)

Submission status: Runtime Error

Solution code:
#とりあえずRE削除目標
from random import randint
import math
#from math import gcd
from fractions import gcd
def is_prime(x):#https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = int(input())
a=[]
for _ in range(n+1):
    a.append(int(input()))
a.reverse()

prm0 = []
prm02 = []
a0 = a[0]

sq = int(a0**(1/2))+3

for i in range(2,sq):
    if a0%i==0:
        prm0.append(i)
        prm02.append(a0//i)
pr_ = prm0+prm02
if a0:
    pr_.append(a0)
pr = []
for p in pr_:
    if is_prime(p):
        pr.append(p)
def f(x,p):
    res = 0
    for i in range(n+1):
        res += pow(x,i,p)*a[i]
    return res
ans_l = []
pr2 = {p for p in pr}
ax = 0
for i in range(50):
    t = randint(5,1000)
    if f(t,p):
        ax = f(t,p)
        break
for _ in range(50):
    ans = ax
    rn = randint(1,10**9)
    ans = gcd(ans,f(rn,ax))
    for p in pr:
        if ans%p and p in pr2:
            pr2.delete(p)

for p in pr2:
    print(p)

Submission status: Runtime Error

Solution code:
#とりあえずRE削除目標
from random import randint
import math
#from math import gcd
from fractions import gcd
def is_prime(x):#https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = int(input())
a=[]
for _ in range(n+1):
    a.append(int(input()))
a.reverse()

prm0 = []
prm02 = []
a0 = a[0]

sq = int(a0**(1/2))+3

for i in range(2,sq):
    if a0%i==0:
        prm0.append(i)
        prm02.append(a0//i)
pr_ = prm0+prm02
if a0:
    pr_.append(a0)
pr = []
for p in pr_:
    if is_prime(p):
        pr.append(p)
def f(x,p):
    res = 0
    for i in range(n+1):
        res += pow(x,i,p)*a[i]
    return res
ans_l = []
pr2 = {p for p in pr}
ax = 0
for i in range(50):
    t = randint(5,1000)
    if f(t,p):
        ax = f(t,p)
        break
for _ in range(50):
    ans = ax
    rn = randint(1,10**9)
    ans = gcd(ans,f(rn,ax))
    for p in pr:
        if ans%p and p in pr2:
            pr2.del(p)

for p in pr2:
    print(p)

Submission status: Runtime Error

Solution code:
#とりあえずRE削除目標
from random import randint
import math
#from math import gcd
from fractions import gcd
def is_prime(x):#https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = int(input())
a=[]
for _ in range(n+1):
    a.append(int(input()))
a.reverse()

prm0 = []
prm02 = []
a0 = a[0]

sq = int(a0**(1/2))+3

for i in range(2,sq):
    if a0%i==0:
        prm0.append(i)
        prm02.append(a0//i)
pr_ = prm0+prm02
if a0:
    pr_.append(a0)
pr = []
for p in pr_:
    if is_prime(p):
        pr.append(p)
#print("test",pr)
def f(x,p):
    res = 0
    for i in range(n+1):
        res += pow(x,i,p)*a[i]
    return res
ans_l = []
pr2 = {p for p in pr}
for _ in range(50):
    ans = a0
    rn = randint(1,a0)
    ans = gcd(ans,f(rn,a0))
    for p in pr:
        if ans%p and p in pr2:
            pr2.remove(p)
    #print(ans)

#ans_l = list(set(ans_l))
#print(ans_l)

for p in pr2:
    print(p)

Submission status: Runtime Error

Solution code:
from random import randint
import math
#from math import gcd
from fractions import gcd
def is_prime(x):#https://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

n = int(input())
a=[]
for _ in range(n+1):
    a.append(int(input()))
a.reverse()

prm0 = []
prm02 = []
a0 = a[0]

sq = int(a0**(1/2))+3

for i in range(2,sq):
    if a0%i==0:
        prm0.append(i)
        prm02.append(a0//i)
pr_ = prm0+prm02
pr_.append(a0)
pr = []
for p in pr_:
    if is_prime(p):
        pr.append(p)
#print("test",pr)
def f(x,p):
    res = 0
    for i in range(n+1):
        res += pow(x,i,p)*a[i]
    return res
ans_l = []
pr2 = {p for p in pr}
for _ in range(50):
    ans = a0
    rn = randint(1,a0)
    ans = gcd(ans,f(rn,a0))
    for p in pr:
        if ans%p and p in pr2:
            pr2.remove(p)
    #print(ans)

#ans_l = list(set(ans_l))
#print(ans_l)

for p in pr2:
    print(p)