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
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
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^{th} row of the triangle are, modulo M. Could you please help him? As a refresher, the i^{th} value (from 1 to N+1) of the N^{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^{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^{th} line of Pascal's triangle is 1\ 4\ 6\ 4\ 1. We calculate each element \operatorname{mod} 6 to get 1\ 4\ 0\ 4\ 1.


Comments

There are no comments at the moment.