#P5173. Circle Ball Passing Game
Circle Ball Passing Game
Circle Ball Passing Game
There are n students standing in a circle. Initially, pG holds a ball. Each student can pass the ball to one of his/her two adjacent neighbors (left or right). When the teacher blows the whistle, the game starts; the ball is passed exactly m times. After exactly m passes, if the ball returns to pG, the passing method is considered valid.
Two passing methods are distinct if and only if the sequence of students (by their order of receiving the ball) differs. For example, consider three students numbered 1, 2, and 3, where pG is student 1. For m = 3, there are 2 valid ways:
- \(1 \to 2 \to 3 \to 1\)
- \(1 \to 3 \to 2 \to 1\)
Determine the number of distinct passing methods such that the ball, starting from pG, returns to pG after exactly \(m\) passes.
inputFormat
The input consists of a single line containing two integers, n and m, separated by space, where:
- n is the number of students in the circle.
- m is the number of times the ball is passed.
outputFormat
Output a single integer representing the number of distinct passing methods that return the ball to pG after exactly \(m\) passes.
sample
3 3
2