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;
#define inf 0x3f3f3f3f
typedef long long ll;
const int N=1e4+5;
int n,a[N],sum[N];
bool vis[N];
int pow(int a,int n)
{
    if(n>=9) return 1e9;
    int ans=1;
    for(int i=1;i<=n;i++) ans=ans*10;
    return ans;
}
bool check(int p)
{
    for(int i=0;i<=p-2;i++) sum[i]=0;
    for(int i=0;i<=n;i++) sum[i%(p-1)]=(sum[i%(p-1)]+a[i])%p;
    for(int i=0;i<=p-2;i++) if(!sum[i]) return false;
    return true;
}
vector<int>v;
int main()
{
    scanf("%d",&n);
    int k=0;
    for(int i=n;i>=0;i--)
    {
        scanf("%d",&a[i]);
        k=__gcd(k,a[i]);
    }
    k=abs(k);
    for(int j=2;j*j<=k;j++)
        if(k%j==0)
    {
        v.push_back(j);
        while(k%j==0) k/=j;
    }
    if(k>1) v.push_back(k);
    for(int i=2;i<=n;i++)
        if(!vis[i])
    {
        if(check(i)) v.push_back(i);
        for(int j=i+i;j<=n;j+=i)
            vis[j]=true;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
        if(i==v.size()-1||v[i]!=v[i+1])
    {
        printf("%d\n",v[i]);
    }
}