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: Runtime Error)

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 1000000007
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,tot=0,pri[1001000],a[10100],tax[10100];
bool ispri[10100];
set<int> ans; 

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

void sieve(int n)
{
	rep(i,2,n)
	{
		if (!ispri[i]) pri[++tot]=i;
		int j;
		for (j=1;j<=tot && i*pri[j]<=n;j++)
		{
			ispri[i*pri[j]]=1;
			if (i%pri[j]==0) break;
		}
	}
}

int gcd(int x,int y)
{
	if (!y) return x;else return gcd(y,x%y);
}

bool chk(int p)
{
	if (a[0]%p) return 0;
	rep(i,0,p-2) tax[i]=0;
	rep(i,0,n) tax[a[i]%(p-1)]=(tax[a[i]%(p-1)]+a[i])%p;
	rep(i,0,p-2) if (tax[i]) return 0;
	return 1;
}

int main()
{
	n=read();sieve(n);
	per(i,n,0) a[i]=read();
	int now=0;
	rep(i,0,n)
	{
		if (a[i])
		{
			if (!now) now=abs(a[i]);
			else now=gcd(abs(a[i]),now);
		}
	}
	now=abs(now);
	
	int rest=now,i;
	for (i=2;i*i<=now;i++)
	{
		if (rest%i) continue;
		while (rest%i==0) rest/=i;
		ans.insert(i);
	}
	
	if (rest>1) ans.insert(rest);
	rep(i,1,tot) if (chk(pri[i])) ans.insert(pri[i]);
	rep(i,1,tot) cout << pri[i] << " ";cout << endl;
	return 0;
	set<int>::iterator it=ans.begin();
	while (it!=ans.end())
	{
		printf("%d\n",*it);
		it++;
	}
	return 0;
}