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++ (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}
int main()
{
	int i,j,k,N;
	// cin >> N >> M;
	cin >> N;
	
	long long int a[10010]={0};
	long long int b[10010] ={0};
	long long int c = 0,d,x;
	for(i=0;i<=N;++i)
	{
		cin >> a[N-i];
		b[i] = 0;
	}
	c = a[0];
	d = c;
	for(i=1;i<=N+10;++i)
	{
		x = (long long int)i;
		d = c;
		for(j=1;j<=N;++j)
		{
			if(a[j] > 0 && c != 0)
				d += (x*a[j])%c;
			else if(c != 0)
				d -= (x*-a[j])%c;
			else
				d += (x*a[j]);
			x *= (long long int)i;
			if(c!=0)
				x %= c;
		}
		if(c!=0)
			c = newton(c,d);
		else
			c = d;
	}
	if(c%2 == 0)
	{
		cout << 2 << endl;
		while(c%2==0)
		{
			c/=2;
		}
	}
	for(i=3;i*i<c;i+=2)
	{
		if(c%i==0)
		{
			cout << i << endl;
			while(c%i==0)
			{
				c/=i;
			}
		}
	}
	if(c>i)
	{
		cout << c << endl;
	}
	return 0;
}