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;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 15000 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int a[MAXN];
int bol[10000];
int vis[10010],vis2[10010];
set<int>s;
int main()
{
    int cnt=0;
    for(int i=2;i<=10000;i++)
    {
        int t=sqrt(i),flag=0;
        for(int j=2;j<=t;j++)
        {
            if(i%j==0)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        bol[++cnt]=i;
    }
    int T,ex=0;
    scanf("%d",&T);
    for(int i=T;i>=0;i--)
    {
        scanf("%d",&a[i]);
        ex=__gcd(a[i],ex);
    }
    for(int i=1;i<=cnt;i++)
    {
        mem(vis,0);
        mem(vis2,0);
        for(int j=T;j>=0;j--)
        {
            if(j>=bol[i]-1)
            {
                vis2[j%(bol[i]-1)+bol[i]-1]+=a[j];
            }
            else
            vis2[j]+=a[j];
            vis[j%(bol[i]-1)]+=a[j];
        }
        int flag=0;
        for(int j=0;j<=10000;j++)
        {
            if(vis[j]%bol[i]!=0||vis2[j]%bol[i]!=0)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            s.insert(bol[i]);
        }
    }
    int t=sqrt(ex+1);
    for(int i=2;i<=t;i++)
    {
        if(ex%i==0)
        {
            s.insert(i);
            while(ex%i==0)
            ex/=i;
        }
    }
    if(ex!=1)
    s.insert(ex);
    for(auto i:s)
    {
        printf("%d\n",i);
    }
}