TLE '17 Contest 4 P5 - Pascal's Tree

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types
The Pascal's-triangle-influenced Christmas Tree.

Fax McClad, Croneria's most decorative bounty hunter, has recently been fascinated with Pascal's triangle. He is in charge of decorating the Cronerian Christmas tree this year, so he does not want to miss an opportunity to reference Pascal's triangle in his design.

He decides to print the first N rows of Pascal's triangle on ornaments to hang on the tree. Since these numbers can get rather large, he will put the values modulo M.

Unfortunately, Fax doesn't know what the values of the N^\text{th} row of the triangle are, modulo M. Could you please help him? As a refresher, the i^\text{th} value (from 1 to N+1) of the N^\text{th} row of Pascal's triangle is \dbinom{N}{i-1}.

Constraints

1 \le N \le 200\,000

2 \le M \le 10^9

SubtaskPointsAdditional Constraints
15N \le 10
210N \le 2000
320M = 10^8+7
420M is prime
545None

Note: It may be helpful to know that 10^8+7 is prime.

Input Specification

The first line will contain 2 integers, N and M.

Output Specification

Output N+1 lines. The i^\text{th} line should contain a single integer, the value of \dbinom{N}{i-1} \bmod M.

Sample Input

4 6

Sample Output

1
4
0
4
1

Explanation for Sample Output

The 4^\text{th} line of Pascal's triangle is 1\ 4\ 6\ 4\ 1. We calculate each element \bmod 6 to get 1\ 4\ 0\ 4\ 1.


Comments