Number Game

3

2 votes
Mathematics, Hard, Fast Fourier transform, Linear Algebra
Problem

You are given N+1 distinct positive integers A1,A2,......,AN+1 and a positive integer M. A polynomial of degree N is defined as follows: 

f(x)=P1xN+P2xN1+..+PNx+PN+1

such that following conditions hold true:

  • f(Ai)=AN+1i i[1,N+1]

  • P1>0

  • P1,P2,.....,PN+1 are integers

A new polynomial is defined as

S(x)=X1xN+X2xN1+..+XNx+XN+1

Such that Xi=|Pi|%M  i[1,N+1] and X1,X2,.......,XN+1 are integers.


Evaluate S(0)%M,S(1)%M,.S(M1)%M .

Input format

  • First line: Two space separated integers N and M
  • Second line: N+1 space separated integers A1,A2,......,AN+1

Output format

  • Output M space-separated integers S(0)%M,S(1)%M,.S(M1)%M

Constraints

1N,M,Ai105

M is prime

Subtasks

  • For 20 Points: 1N,M,Ai1000
  • For 80 Points: Original constraints
Sample Input
2 13
1 2 3
Sample Output
6 10 0 2 3 3 2 0 10 6 1 8 1 
Time Limit: 4
Memory Limit: 256
Source Limit:
Explanation

Required polynomial F(x) is 6x211x+6 and hence S(x) is 6x2+11x+6. Hence S(0)%M=6, S(1)%M=23%13=10 and so on.

Editor Image

?