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: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL N = 10010;
LL a[N], b[N], w[N];
bool v[N];

int main()
{
    register LL n, p, cnt = 0;
    scanf("%lld", &n);
    scanf("%lld", &a[n]);
    p = abs(a[n]), b[n] = a[n];
    for (register LL i = n - 1; i >= 0; --i) {
        scanf("%lld", &a[i]);
        p = __gcd(p, abs(a[i])), b[i] = a[i];
    }
    for (register LL i = 2, q; i <= n; ++i) {
        if (v[i] == 1) continue;
        w[++cnt] = i, q = n / i;
        for (register LL j = i; j <= q; ++j) v[i * j] = 1;
    }
    for (register LL i = 1; i <= cnt; ++i) {
        for (register LL j = 0; j <= n; ++j) a[j] = b[j];
        // for (register LL j = n - (w[i] - 1); j >= 0; --j) a[j] = (a[j] + a[j + (w[i] - 1)]) % w[i], a[j + (w[i] - 1)] = 0;
        for (register LL j = n; j >= w[i] - 1; --j)
            a[j - w[i] + 1] = (a[j - w[i] + 1] + a[j]) % w[i], a[j] = 0;
        for (register LL j = n; j >= 0; --j) {
            if (a[j] % w[i] != 0) {
                w[i] = 0;
                break;
            }
        }
    }
    for (register LL i = 2; i <= sqrt(p); ++i) {
        if (p % i == 0) {
            w[++cnt] = i;
            while (p % i == 0) p = p / i;
        }
    }
    if (p > 1) w[++cnt] = p;
    sort(w + 1, w + cnt + 1);
    for (register LL i = 1; i <= cnt; ++i) {
        if (w[i] == 0) continue;
        if (w[i] == w[i - 1]) continue;
        printf("%lld\n", w[i]);
    }
    return 0;
}