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: Accepted)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=1e4+10;
int prime[MAXN],cnt=0,ism[MAXN];
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int a[MAXN],n;
int sum[MAXN];
bool check(int p)
{
	for(int i=0;i<p-1;++i)
		sum[i]=0;
	for(int i=0;i<=n;++i)
	{
		sum[i%(p-1)]=(sum[i%(p-1)]+a[i])%p;
	}
	for(int i=0;i<p-1;++i)
		if(sum[i]%p)
			return false;
	return true;
}
void init()
{
	ism[1]=1;
	for(int i=2;i<=n;++i)
	{
		if(!ism[i])
			prime[++cnt]=i;
		for(int j=1;j<=cnt;++j)
		{
			if(1LL*prime[j]*i>n)
				break;
			ism[i*prime[j]]=1;
			if(i%prime[j]==0)
				break;
		}
	}
}
set<int> ans;
void pr()
{
	for(auto x:ans)
		printf("%d\n",x);
}
int main()
{
	n=read();
	init();
	int g=0;
	for(int i=n;i>=0;--i)
	{
		a[i]=read();
		if(a[i])
			g=gcd(g,abs(a[i]));
	}
	for(int i=2;i*i<=g;++i)
	{
		if(g%i==0)
		{
			ans.insert(i);
			while(g%i==0)
				g/=i;
		}
	}
	if(g>1)
		ans.insert(g);
	for(int i=1;i<=cnt;++i)
	{
		if(a[0]%prime[i]==0 && check(prime[i]))
			ans.insert(prime[i]);
	}
	pr();
	return 0;
}