atcoder#AGC009E. Eternal Average
Eternal Average
Score : points
Problem Statement
There are zeros and ones written on a blackboard. Starting from this state, we will repeat the following operation: select of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those numbers. Here, assume that is divisible by .
Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.
Find the number of the different possible values taken by this rational number, modulo .
Constraints
- is divisible by .
Input
The input is given from Standard Input in the following format:
Output
Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo .
2 2 2
5
There are five possible values for the number that will be eventually left on the blackboard: , , , and .
For example, can be eventually left if we:
- Erase and , then write .
- Erase and , then write .
- Erase and , then write .
3 4 3
9
150 150 14
937426930