This page is still under construction.

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

Polynomial Evaluation

Time limit1sMemory limit1024 MB

Summary
Given a polynomial of degree N and a prime P, print f(x) mod P for every x from 0 to P-1.
Level

Medium5 of 10

Topics
Number theory, Math, Array
Solved
No attempts yet

Problem

A polynomial f(x)=aNxN+⋯+a1x+a0f(x) = a_Nx^N + \cdots + a_1x + a_0 of degree NN and a prime PP are given. A prime is a number divisible only by 11 and itself. 11 is not prime.

Write a program that computes f(0) mod Pf(0) \bmod P, f(1) mod Pf(1) \bmod P, ⋯\cdots, f(P−1) mod Pf(P-1) \bmod P. Here u mod vu \bmod v is the remainder when uu is divided by vv.

Input

The first line contains two integers NN and PP (0≤N≤1060 \le N \le 10^6, 1≤P≤1031 \le P \le 10^3, PP is prime), separated by a space.

The second line contains N+1N+1 integers aN,⋯ ,a1,a0a_N, \cdots, a_1, a_0 (0≤ai≤1090 \le a_i \le 10^9), separated by spaces.

Output

Print PP lines. The ii-th line contains f(i−1) mod Pf(i-1) \bmod P.

Examples3

  1. Example 1

    Input
    3 2
    1 1 1 1
    
    Expected output
    1
    0
    
  2. Example 2

    Input
    5 7
    9 8 7 6 5 4
    
    Expected output
    4
    4
    6
    3
    2
    5
    4
    
  3. Example 3

    Input
    8 17
    10 55 23 5 8 24 9 1 77
    
    Expected output
    9
    8
    5
    8
    9
    4
    6
    11
    7
    8
    4
    1
    13
    15
    13
    7
    8