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>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

map<long long,int> mp;
vector<long long> prime_factorization(long long n){
    vector<long long> v;
    if(n==1) v.push_back(1);
    long long i=2;
    while(n>1){
        if(n<i*i){
            v.push_back(n);
            mp[n]++;
            return v;
        }
        if(n%i==0){
            n/=i;
            v.push_back(i);
            mp[i]++;
        }else{
            i++;
        }
    }
    return v;
}

long long modpow(long long a,long long n,long long MOD){
    long long x=1;
    while(n>0){
        if(n&1){
            x=x*a%MOD;
        }
        a=a*a%MOD;
        n>>=1;
    }
    return x;
}

int main(){
    int n; cin>>n;
    long long a[n+1]; rep(i,n+1) cin>>a[i];
    prime_factorization(abs(a[n]));
    for(auto x:mp){
        long long mod=x.first;
        bool flg=1;
        for(long long i=1;i<200;i++){
            long long sum=0;
            for(int j=0;j<n+1;j++){
                sum+=a[j]*modpow(i,n-j,mod)%mod;
                sum%=mod;
            }
            if(sum%mod!=0){
                flg=0;
                break;
            }
        }
        if(flg){
            cout<<mod<<endl;
        }
    }
    return 0;
}