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 <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 110000

ll gcd(ll x,ll y){
    for(;y;swap(x,y))x%=y;
    return x;
}
ll a[11000];
main(){
    ll n=in();
    ll g=0;
    for(int i=n;i>=0;i--){
        a[i]=in();
        g=gcd(g,a[i]);
    }
    vector<ll> ans;
    for(ll i=2;i*i<=g;i++){
        if(g%i==0){
            ans.pb(i);
            while(g%i==0){
                g/=i;
            }
        }
    }
    if(g>1)ans.pb(g);
    int prime[33000]={};
    prime[0]=prime[1]=1;
    vector<ll> v;
    rep2(i,2,n){
        if(!prime[i]){
            v.pb(i);
            for(int j=i*2;j<=23000;j+=i){
                prime[j]=1;
            }
        }
    }
    for(auto p:v){
        ll s[11000]={};
        if(a[0]%p!=0)continue;
        rep(i,n+1){
            s[i%(p-1)]+=a[i]%p;
        }
        bool flag=true;
        rep(i,p-1){
            if(s[i]%p!=0)flag=false;
        }
        if(flag&&(a[0]%p==0))ans.pb(p);
    }
    sort(ALL(ans));
    ans.erase(unique(ALL(ans)),ans.end());
    for(auto e:ans)cout<<e<<endl;
}