luogu#P5173. 传球
传球
Background
As the middle school entrance exam is approaching, pG’s head teacher decides to hold a PE class to help everyone relax.
Problem Description
The teacher leads pG’s classmates to play a ball-passing game.
The rules are as follows: students stand in a circle. One of them holds a ball at the beginning. When the teacher blows the whistle, they start passing the ball. Each student can pass the ball to either of their two neighbors (left or right, either is allowed). When the teacher blows the whistle again, passing stops. At that moment, the student who is holding the ball and did not pass it out is the loser, and must perform a show for everyone.
pG asks an interesting question: how many different passing methods make it so that the ball, starting from pG, returns to pG after being passed times? Two passing methods are considered different if and only if the sequence of students who receive the ball (in the order of receiving) is different. For example, if there are three students numbered , , , and pG is student , then the ways for the ball to return to pG after passes are and , for a total of ways.
Input Format
One line containing two integers separated by a space.
Output Format
Output integer, the number of methods that satisfy the requirement.
Since the answer may be very large, output it modulo .
3 3
2
30 30
155117522
1234 12345678
424074635
Hint
For of the testdata, .
For of the testdata, .
The testdata has a certain gradient.
Translated by ChatGPT 5