message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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.
Examples
Input
2
7
-7
14
Output
2
7
Input
3
1
4
1
5
Output
Input
0
998244353
Output
998244353
Submitted Solution:
```
inpl = lambda: list(map(int,input().split()))
N = int(input())
a = []
for i in range(N):
a.append(int(input()))
from functools import reduce
import fraction
#import math as fraction
def gcd_list(numbers):
return reduce(fraction.gcd, numbers)
g = gcd_list(a)
plist = []
while i*i <= g:
if g % i == 0:
while g % i == 0:
g %= i
i += 1
if g > 1:
plist.append(g)
for p in plist:
print(p)
``` | instruction | 0 | 108,473 | 22 | 216,946 |
No | output | 1 | 108,473 | 22 | 216,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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.
Examples
Input
2
7
-7
14
Output
2
7
Input
3
1
4
1
5
Output
Input
0
998244353
Output
998244353
Submitted Solution:
```
import math
from fractions import gcd
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
def isprime(x):
q = int(math.sqrt(x)) # int() rounds to zero
for i in range(2,q+1): # upto q
if x%i == 0:
return False
return True
def prime_division(x):
q = int(math.sqrt(x))
a = []
for i in range(2,q+1):
ex = 0
while x%i == 0:
ex += 1
x //= i
if ex>0:
a.append([i,ex])
if x>q:
a.append([x,1])
return a
n = inn()
a = [0] * (n+1)
for i in range(n+1):
a[n-i] = inn()
ddprint(a)
g = a[n]
for i in range(n):
g = gcd(g, a[i])
p = prime_division(abs(g))
b = []
for x in p:
if x[0] != 1:
b.append(x[0])
ddprint("b:")
ddprint(b)
if a[0] != 0:
p0 = prime_division(abs(a[0]))
ps = [x[0] for x in p0 if x[0]<30]
else:
ps = [2,3,5,7,11,13,17,19,23,29]
ddprint("ps:")
ddprint(ps)
for p in ps:
if p in b:
continue
ok = True
for r in range(1,p):
v = a[0]
r2i = 1
for i in range(1,n+1):
r2i = (r2i * r) % p
v = (v + a[i] * r2i) % p
if v != 0:
ok = False
break
if ok:
b.append(p)
b.sort()
for x in b:
print(x)
``` | instruction | 0 | 108,474 | 22 | 216,948 |
No | output | 1 | 108,474 | 22 | 216,949 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.