luogu#P5059. 中国象棋

中国象棋

Background

gjm really likes studying board game problems. Recently, he has been researching Chinese chess QwQ.

Problem Description

Now, in gjm’s mind there is an N×NN \times N chessboard, with a total of N×NN \times N cells. gjm starts placing pawns on the grid points of the board. It is known that a pawn only attacks pieces on the grid point one step to its left and one step to its right. Now gjm places any number of pawns on the board, satisfying:

  1. Each row has at least two pawns placed.
  2. No two pawns attack each other.

gjm now wants to know: how many pawn placement schemes satisfy the above conditions? Since the answer may be very large, you only need to output the number of schemes modulo PP.

Two schemes are considered different if and only if there exists at least one grid point where the placement differs.

Input Format

One line with two positive integers, NN and PP.

Output Format

One line with one integer, the number of pawn placement schemes on an N×NN \times N board modulo PP.

1 10007
0
2 1000000000
1
7 1000000000
612231936

Hint

Explanation for Sample 1

Obviously, there is no valid scheme.

Explanation for Sample 2 (00 means no pawn on the grid point, 11 means there is a pawn on the grid point.)

There is only one scheme:

11 00 11

11 00 11

11 00 11

This sample and its explanation are correct.

Explanation for Sample 3

It is too large to list all schemes, so no explanation is given.

Constraints:

For 20%20\% of the testdata, N100N \le 100, P109P \le 10^{9}.

For 50%50\% of the testdata, N105N \le 10^5, P109P \le 10^{9}.

For 100%100\% of the testdata, N1018N \le 10^{18}, P1018P \le 10^{18}.

By: Endless Learning.

Translated by ChatGPT 5