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

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

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

i32 gcd (i32 a, i32 b) {
  a = ABS(a);
  b = ABS(b);
  if (a == 0) return b;
  if (b == 0) return a;
  i32 r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int cmp (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = n; i >= 0; --i) {
    scanf ("%" SCNi32, a + i);
  }
  uint8_t *p = (uint8_t *) calloc (n + 1, sizeof (uint8_t));
  for (i32 i = 2; i <= n; ++i) {
    p[i] = 1;
  }
  for (i32 i = 2; i * i <= n; ++i) {
    if (p[i] == 0) continue;
    for (i32 j = i * i; j <= n; j += i) {
      p[j] = 0;
    }
  }
  i64 *dp = (i64 *) calloc (n + 1, sizeof (i64));
  i32 *ans = (i32 *) calloc (n + 1 + 30, sizeof (i32));
  i32 len = 0;
  for (i32 i = 2; i <= n; ++i) {
    if (p[i] == 0) continue;
    for (i32 j = 0; j <= n; ++j) {
      dp[j] = a[j];
    }
    const i32 prime = i;
    for (i32 j = n; j >= prime; --j) {
      dp[j - prime + 1] += dp[j];
      dp[j] = 0;
    }
    i32 ok = 1;
    for (i32 j = prime - 1; j >= 0; --j) {
      if (dp[j] != 0 && dp[j] % prime != 0) {
	ok = 0;
      }
    }
    if (ok) {
      ans[len++] = prime;
    }
  }
  i32 g = ABS(a[0]);
  for (i32 i = 1; i <= n; ++i) {
    g = gcd (g, a[i]);
  }
  for (i32 i = 2; i * i <= g; ++i) {
    if (g % i != 0) continue;
    ans[len++] = i;
    while (g % i == 0) {
      g /= i;
    }
  }
  if (g > 1) {
    ans[len++] = g;
  }
  qsort (ans, len, sizeof (i32), cmp);
  for (i32 i = 0; i < len; ++i) {
    if (i > 0 && ans[i - 1] == ans[i]) continue;
    printf ("%" PRIi32 "\n", ans[i]);
  }
}

int main (void) {
  run();
  return 0;
}