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 Nth row of the triangle are, modulo M. Could you please help him? As a refresher, the ith value (from 1 to N+1) of the Nth row of Pascal's triangle is (Ni1).

Constraints

1N200000

2M109

SubtaskPointsAdditional Constraints
15N10
210N2000
320M=108+7
420M is prime
545None

Note: It may be helpful to know that 108+7 is prime.

Input Specification

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

Output Specification

Output N+1 lines. The ith line should contain a single integer, the value of (Ni1)modM.

Sample Input

Copy
4 6

Sample Output

Copy
1
4
0
4
1

Explanation for Sample Output

The 4th line of Pascal's triangle is 1 4 6 4 1. We calculate each element mod6 to get 1 4 0 4 1.


Comments