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: Time Limit Exceeded)

 /*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
const string FILENAME = "input";
const int MAXN = 10228;

int n;
long long a[MAXN];
bool bad[MAXN];
long long g[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> n;
	long long kek = 0;
	for (int i = n; i >= 0; i--) {
		cin >> a[i];
		kek += a[i];
	}
	kek = abs(kek);
	if (kek == 0) {
		if (a[0] != 0) {
			kek = abs(a[0]);
		} else {
			// for (int cur = 1; ; cur++) {
			// long long g = 1;
			// for (int i = 0; i <= n; i++) {
			// 	kek += g * a[i];
			// 	g *= cur;
			// }
			// if (kek != 0) {
			// 	kek = abs(kek);
			// 	break;
			// }
			// }
		}
	}
	vector<long long> st;
	for (int j = 2; j <= 10003; j++) {
		if (!bad[j]) {
			st.pb(j);
			for (int k = j * j; k <= 10003; k+= j) {
				bad[k] = true;
			}
		}
	}
	for (int i = 0; i <= n; i++) {
		int k = abs(a[i]);
		if (k == 0 || k == 1) {
			continue;
		}
		int cur = 2;
		while (cur * cur <= k) {
			if (k % cur == 0) {
				while (k % cur == 0) {
					k /= cur;
				}
				if (cur > 10003) {
					st.pb(cur);
				}
			}
			cur++;
		}
		if (k != 1) {
			if (k > 10003) {
				st.pb(k);
			}
		}
	}
	long long keks = kek;
	long long cur = 2;
	while (cur * cur <= kek) {
		if (kek % cur == 0) {
			while (kek % cur == 0) {
				kek /= cur;
			}
			if (cur > 10003) {
				st.pb(cur);
			}
		}
		cur++;
	}
	if (kek != 1) {
		if (kek > 10003) {
			st.pb(kek);
		}
	}
	sort(all(st));
	st.resize(distance(st.begin(), unique(all(st))));
	for (auto x: st) {
		//cout << x << endl;
		memset(g, 0, sizeof(g));
		for (int i = 0; i <= n; i++) {
			long long f = (a[i] >= 0 ? a[i] % x: x - abs(a[i]) % x);
			f %= x;
			g[i % (x - 1)] += f;
			g[i % (x - 1)] %= x;
		} 
		bool bad = false;	
		long long sum = 0;
		for (int i = 0; i <= n; i++) {
			if (g[i] < 0) {
				g[i] += x;
			}
			sum += g[i];
			sum %= x;
		}
		for (int i = 0; i <= n; i++) {
			if (g[i] != 0) {
				bad = true;
				break;
			}
		}
		if (!bad && keks % x == 0) {
			cout << x << '\n';
		} else {
			// if (sum == 0 && g[0] == 0 && keks % x == 0) {
			// 	bad = false;
			// 	for (long long i = 1; i <= x - 1; i++) {
			// 		__int128 cur = 1;
			// 		for (int j = 0; j <= min((long long)n, x - 2); j++) {
			// 			sum += (cur * g[j]) % x;
			// 			sum %= x;
			// 			cur = (cur * i) % x;	
			// 		}
			// 		if (sum != 0) {
			// 			bad = true;
			// 			break;
			// 		}
			// 	}
			// 	if (!bad) {
			// 		cout << x << '\n';
			// 	}
			// }
		}
	}
	return 0; 	
}