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 JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};
function sieveOfEratosthenes(e){const t=new Array(e+1).fill(!0);t[0]=!1,t[1]=!1;const n=[];for(let r=2;r<=e;r+=1)if(!0===t[r]){n.push(r);let f=r*r;for(;f<=e;)t[f]=!1,f+=r}return n}

var primes = sieveOfEratosthenes(100000);
function main(input) {
  var o = new I(input);

  var n = o.a();
  var a = [];

  for (var i = 0; i <= n; i++) {
    a.push(o.a());
  }
  a = a.reverse();

  let agcd = a[0];
  for (var i = 1; i <= n; i++) {
    agcd = gcd(agcd, a[i]);
  }

  a = a.map(x => x/agcd);

  var ans = [];
  primes.filter(p => p <= n).forEach(prime => {
    if (a[0] % prime !== 0) return;
    for (var i = 1; i < prime; i++) {
      var j = i;
      var ajsum = 0;
      while (j <= n) {
        ajsum += a[j];
        j += prime - 1;
      }
      if (ajsum % prime !== 0) return;
    }
    ans.push(prime);
  });

  var i = 0;
  while (agcd > 1 && i < primes.length) {
    if (agcd % primes[i] === 0) {
      ans.push(primes[i]);
      while(agcd % primes[i] === 0) {
        agcd = agcd / primes[i];
      }
    }
    i += 1;
  }
  if (agcd > 1) {
    ans.push(agcd);
  }

  ans.sort((a,b) => a - b);
  var prev;
  for (var i = 0; i < ans.length; i++) {
    if (prev !== ans[i]) {
      console.log(ans[i]);
    }
    prev = ans[i];
  }
}

function gcd(a, b) {
  if (b === 0) return a;
  return gcd(b, a%b);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));