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 rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
5
1
2
4
-2
-5
0
*/

ll n,g;
vector<ll> p,fact,a;
set<ll> ans;

void prime_list(ll n,vector<ll>& p){
	ll visited[300010]={};
	reg(i,2,n){
		if(visited[i]==0){
			p.push_back(i);
			reg(j,2,n){
				if(j*i>n)break;
				visited[i*j]=1;
			}
		}
	}
}
void factoring(ll n,vector<ll>& v,vector<ll>& p){
	rep(i,p.size()){
		while(n%p[i]==0){
			n/=p[i];
			v.push_back(p[i]);
		}
	}
	if(n>1)v.push_back(n);//残渣が素数でないといけない。
}

long long gcd(long long a,long long b){
	if(b==0)return a;
	return gcd(b,a%b);
}

bool division(vector<ll> v,ll p){//ここは変更するのでコピーにしないといけない
	bool ok=true;
	rep(i,v.size())v[i]%=p;
	rep(i,v.size()){
		//今回は計算量短縮のために多項式を陽に与える
		if(i+(p-1)>=v.size()-1)break;//最後は定数なので変えられない
		ll t=v[i];
		v[i]-=t;
		v[i+(p-1)]+=t;
	}
	rep(i,v.size())if(v[i]%p!=0)ok=false;
	return ok;
}

void init(){
	cin>>n;
	reg(i,0,n){
		ll b;
		cin>>b;
		a.push_back(b);
	}
	g=a[0];
	reg(i,1,n)g=gcd(g,abs(a[i]));
	prime_list(100010,p);
	factoring(g,fact,p);
	rep(i,fact.size())ans.insert(fact[i]);
	cerr<<"初期化終了"<<endl;
}

int main(void){
	init();
	rep(i,p.size()){
		if(p[i]>n)break;
		if(division(a,p[i]))ans.insert(p[i]);
	}
	for(auto itr=ans.begin();itr!=ans.end();itr++){
		cout<<*itr<<endl;
	}
	return 0;
}