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

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}

bool isprime(long long x){
  long long i;
  if(x==1){return false;}
  if(x==2){return true;}
  if(x%2==0){return false;}
  for(i=3;i*i<=x;i+=2){
    if(x%i==0){return false;}
  }
  return true;
}

long long calcmod(long long x,long long m){
  if(x>=0){return x%m;}
  return (m-((-x)%m))%m;
}

long long n,a[16384];

bool judge(long long p){
  if(!isprime(p)){return false;}
  long long i,b[16384];
  for(i=0;i<=n;i++){b[i]=calcmod(a[i],p);}
  for(i=n;i>=p-1;i--){
    b[i-(p-1)]+=p;
    b[i-(p-1)]-=b[i];
    b[i-(p-1)]%=p;
  }
  for(i=p-2;i>=0;i--){
    if((b[i]%p)!=0){return false;}
  }
  return true;
}

int main(){
  long long i,g;
  long long res[16384],rp=0,t;
  scanf("%lld",&n);
  for(i=n;i>=0;i--){scanf("%lld",&a[i]);}
  g=llzt(0,a[n]);
  for(i=n-1;i>=0;i--){
    g=llgcd(g,llzt(0,a[i]));
  }
  for(i=n;i>=0;i--){a[i]/=g;}
  for(i=2;i*i<=g;i++){
    if((g%i)!=0){continue;}
    if(isprime(i)){res[rp]=i;rp++;}
    while((g%i)==0){g/=i;}
  }
  if(isprime(g)){res[rp]=g;rp++;}
  t=a[0];
  for(i=2;i*i<=t;i++){
    if((a[0]%i)!=0){continue;}
    if(judge(i)){res[rp]=i;rp++;}
    while((t%i)==0){t/=i;}
  }
  if(judge(t)){res[rp]=t;rp++;}
  qsort(res,rp,sizeof(long long),llsortfncsj);
  res[rp]=-1;
  for(i=0;i<rp;i++){
    if(res[i]==res[i+1]){continue;}
    printf("%lld\n",res[i]);
  }
  return 0;
}