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 int max_n=10005;
int n;
int a[max_n];
bool is(int n)
{
    for(int i=2;i<=sqrt(n);i++)if(n%i)return false;
    return true;
}
int f(int x,int mod)
{
    int res=0;
    for(int i=n;i>=0;i--)res=(1ll*res*x+a[i])%mod;
    return res;
}
bool check(int p)
{
    for(int i=0;i<p;i++)if(f(i,p))return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    int d=0;
    for(int i=n;i>=0;i--)scanf("%d",a+i),d=__gcd(d,a[i]);
    d=abs(d);
    for(int i=n;i>=0;i--)a[i]/=d;
    vector<int> ans;
    for(int i=2;i<=sqrt(d);i++)
    {
        if(d%i)continue;
        while(d%i==0)d/=i;
        ans.push_back(i);
    }
    if(d!=1)ans.push_back(d);
    for(int i=2;i<=n;i++)
    {
        if(is(i))
        {
            if(check(i))ans.push_back(i);
        }
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    for(auto p:ans)printf("%d ",p);
    printf("\n");
    return 0;
}