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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{
    public void AtCoder()
    {
        string[] s;
        s = Console.ReadLine().Split(' ');
        int n;
        n = int.Parse(s[0]);

        int[] a = new int[n+1];
        for (int i = n; i > -1; i--)
        {
            s = Console.ReadLine().Split(' ');
            a[i] = int.Parse(s[0]);
        }

        long tmpl = 0;
        bool[] prime = new bool[100000];
        for (int i = 2; i < 100000; i++) prime[i] = true;
        for (int i = 2; i < 100000; i++)
        {
            if (prime[i])
            {
                tmpl = i * 2;
                while (tmpl < 100000)
                {
                    prime[tmpl] = false;
                    tmpl += i;
                }
            }
        }

        int tmp = Math.Abs(a[0]);
        List<int> list = new List<int>();
        for(int i=2; i<100000; i++)
        {
            if(prime[i] && tmp % i == 0)
            {
                list.Add(i);
            }
        }
        for(int i=2; i<100000; i++)
        {
            if (tmp % i == 0) break;
            if(i == 99999) list.Add(tmp);
        }

        Mod mod = new Mod(100000);
        int[] k = new int[n + 1];
        int x = 0;
        long ans = 0;
        bool f = false;

        DebugWL(list.Count);
        for(int i=0; i<list.Count; i++)
        {
            f = true;
            x = list[i];
            mod.p = x;
            /*
            for(int j=1; j<=n; j++)
            {
                k[j] = j;
                while(k[j] >= x)
                {
                    k[j] = k[j] / j + k[j] % x;
                }
            }
            */
            for (int l = 797; l < 820; l++)
            {
                for (int j = 1; j <= n; j++)
                {
                    tmpl = mod.Pow(l, k[j]);
                    if (a[j] > 0) tmpl *= a[j];
                    else tmpl *= (x - ((-a[j]) % x));
                    tmpl %= x;
                    ans += tmpl;
                    ans %= x;                                
                }
                if (ans != 0) f = false;
            }
            if (f) Console.WriteLine(x);
        }
    }

    // Mod(int n)
    // int[] fac: factors (1-indexed)
    // int n: the length of fac

    // int .Ncr(n,r): nCr
    // int .Fac(n): n!%p
    // int .Pow(n,m): n^m%p

    public class Mod
    {
        public int p = 1000000007;
        int[] fac;

        public Mod(int n)
        {
            fac = new int[n + 1];
            for (int i = 1; i <= n; i++) fac[i] = -1;
            fac[0] = 1;
        }

        public int Ncr(int n, int r)
        {
            if (n < r) return 0;
            if (r == 0 | n == r) return 1;
            long a = Fac(n);
            a = a * Pow(Fac(n - r), p - 2) % p;
            a = a * Pow(Fac(r), p - 2) % p;
            return (int)a;
        }

        public int Fac(int n)
        {
            if (fac[n] >= 0) return fac[n];
            long k = 1;
            for (long i = 1; i <= n; i++)
            {
                k = k * i % p;
            }
            fac[n] = (int)k;
            return fac[n];
        }

        public int Pow(int n, int m)
        {
            if (m == 0) return 1;
            if (m == 1) return n;
            long a = 1;
            if (m % 2 == 0)
            {
                a = Pow(n, m / 2);
                a = a * a % p;
            }
            else
            {
                a = Pow(n, m / 2);
                a = a * a % p;
                a = a * n % p;
            }
            return (int)a;
        }
    }

    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}