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

Solution in Ruby (2.3.3) (judge verdict: Runtime Error)

N = gets.to_i

as = []
N.times{|i|
	as << [N - i, gets.to_i]
}
a0 = gets.to_i

def decompose(n)
	(2..Math.sqrt(n).ceil).each{|i|
		if n % i == 0
			return [i] + decompose(n / i)
		end
	}
	return [n]
end

def calc_gcm(a, b)
	if a < b
		calc_gcm(b, a)
	elsif b == 0
		a
	else
		calc_gcm(a % b, b)
	end
end

gcm = as.length > 0 ? as[0][1].abs : 1
(1...N).each{|i|
	gcm = calc_gcm(gcm, as[i][1].abs)
	if gcm == 1
		break
	end
}
if gcm > 1
	as.each{|pair|
		pair[1] /= gcm
	}
end

#p gcm
#p as
#p a0

def divide(as, n)
	while as.length > 0
		left = as.clone
		first = left.shift
		p, k = first
		p -= 1
		if left.length > 0 && left[0][0] == p
			new_k = left[0][1] - k * n
			if new_k != 0
				left[0] = [p, new_k]
			else
				left.shift
			end
		else
			left.unshift([p, -k * n])
		end
		
		if left.length == 1
			return nil
		end
		
		as = left
	end
	
	return as
end

k_list = []
k = 1
while k <= 1000 && as.length > 0
	if new_as = divide(as, k)
		as = new_as
		k_list << k
	elsif new_as = divide(as, -k)
		as = new_as
		k_list << -k
	else
		k += 1
	end
end

#p k_list
#p as

def check(k_list, n)
	if k_list.length < n
		return false
	end
	(1...n).each{|i|
		if k_list.index(i) == nil && k_list.index(-n + i) == nil
			return false
		end
	}
	return true
end

answers = []
decompose(a0).sort.uniq.each{|n|
	if as.length == 0 || gcm % n == 0
		answers << n
	else
		if check(k_list, n)
			answers << n
		end
	end
}

answers.each{|n|
	puts n
}