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: Runtime Error)

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

bool primes[1000001];

int n;
vector<ll> p;
ll a[10001];

void init() {
    for (int i = 2; i <= 1000000; i++) primes[i] = true;
    for (int i = 2; i*i <= 1000000; i++) {
        if (!primes[i]) continue;
        for (int j = i*2; j <= 1000000; j += i) {
            primes[j] = false;
        }
    }
}

bool calc_f(ll mod, ll x) {
    ll ret = 0;
    ll X = 1;
    for (int i = n-1; i >= 0; i--) {
        ret = (ret + X*a[i] + MOD*mod)%mod;
        X = X * x % mod;
    }
    return ret==0;
}

int main() {
    init();
    cin >> n;
    n++;
    rep(i,n) cin >> a[i];
    ll A = 0;
    rep(i,n) A += a[i];
    for (int i = 2; i*i <= abs(a[n-1]); i++) {
        if (!primes[i]) continue;
        if (A%i == 0) p.push_back(i);
        while (A%i == 0) A /= i;
    }
    if (A != 1) p.push_back(A);
    std::chrono::system_clock::time_point  start, end;
    start = std::chrono::system_clock::now();
    while (true) {
        end = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
        if (elapsed > 1800) break;
        vector<ll> q;
        for (int i = 0; i < p.size(); i++) {
            if (calc_f(p[i], rand()%INF+1)) {
                q.push_back(p[i]);
            }
        }
        p = q;
    }
    rep(i,p.size()) cout << p[i] << endl;
}