This page is still under construction.

Parts of this page are still being built. What you see may change.

Complex Integer Solutions

Time limit8sMemory limit512 MB

Summary
Given an integer polynomial of degree at most 10, find all Gaussian integer roots and print them sorted by real then imaginary part.
Level

Medium7 of 10

Topics
Math, Number theory, Brute force, Implementation
Solved
No attempts yet

Problem

Let f(x)=a0+a1x+a2x2+⋯+adxdf(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_d x^d, where each aia_i (0≤i≤d0 \le i \le d) is an integer constant and ad≠0a_d \ne 0. Write a program that finds all complex integer solutions of f(x)=0f(x) = 0. A complex integer is a complex number whose real and imaginary parts are both integers.

Input

The input consists of two lines. The first line contains dd, the degree of f(x)f(x). The second line contains d+1d+1 integers a0,a1,…,ada_0, a_1, \ldots, a_d. The following are guaranteed: 1≤d≤101 \le d \le 10, ∣ai∣≤106|a_i| \le 10^6, and ad≠0a_d \ne 0.

Output

Print two lines. On the first line, print the number mm of complex integer solutions. On the second line, print the mm solutions separated by spaces. Count and print each solution exactly once even if it is a multiple root. Sort the solutions in ascending order of real part, then imaginary part, and print them in the following format: 0, -2, i, -3i, 2+i, 3-4i.

Examples2

  1. Example 1

    Input
    4
    -2 0 0 0 2
    
    Expected output
    4
    -1 -i i 1
    
  2. Example 2

    Input
    8
    0 0 25 15 17 -10 1 -1 1
    
    Expected output
    5
    -1-2i -1+2i 0 2-i 2+i