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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

vector<int> makePrimeList(){
	int range = 1000000;
	vector<int> ret;
	vector<bool> notp(range);

	notp[0] = notp[1] = true;
	for(int i = 2;i < range;i++){
		if(!notp[i]){
			ret.PB(i);
			for(int j = 2 * i;j < range;j += i){
				notp[j] = true;
			}
		}
	}

	return ret;
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

	ll n;cin >> n;
	vector<ll> v(n+1);
	REV(i, n+1)cin >> v[i];

	auto p = makePrimeList();

	vector<int> ans;
	for(ll i = 0;p[i] <= n;i++){
		if(!(v[0] == 0 || v[0] % p[i] == 0))continue;
		vector<ll> now(p[i]-1, 0);
		for(int j = 1;j <= n;j++){
			now[(j-1)%(p[i]-1)] += v[j];
		}
		bool flag = true;
		REP(j, p[i]-1){
			if(abs(now[j]) % p[i] != 0)flag = false;
		}
		if(flag)ans.PB(p[i]);
	}

	v[n] = abs(v[n]);
	REP(i, p.size()){
		if(p[i] > n &&  v[n] % p[i] == 0){
			bool flag = true;
			REP(j, n)if(abs(v[j]) % p[i])flag = false;
			if(flag)ans.PB(p[i]);
		}
		while(v[n] != 0 && v[n] % p[i] == 0)v[n] /= p[i];
	}

	if(v[n] > 1){
		bool flag = true;
		REP(i, n)if(abs(v[i]) % v[n])flag = false;
		ans.PB(v[n]);
	}

	REP(i, ans.size()){
		cout << ans[i] << endl;
	}

	return 0;
}