[Solution] Game of AI (easy version) Codeforces Solution
This is the easy version of this problem. The difference between easy and hard versions is the constraint on and the time limit. Also, in this version of the problem, you only need to calculate the answer when . You can make hacks only if both versions of the problem are solved.
Cirno is playing a war simulator game with towers (numbered from to ) and bots (numbered from to ). The -th tower is initially occupied by the -th bot for .
Before the game, Cirno first chooses a permutation of length (A permutation of length is an array of length where each integer between and appears exactly once). After that, she can choose a sequence ( and for all ).
The game has rounds of attacks. In the -th round, if the -th bot is still in the game, it will begin its
attack, and as the result the -th tower becomes occupied by the -th bot; the bot that previously occupied the -th tower will no longer occupy it. If the -th bot is not in the game, nothing will happen in this round.
After each round, if a bot doesn't occupy any towers, it will be eliminated and leave the game. Please note that no tower can be occupied by more than one bot, but one bot can occupy more than one tower during the game.
At the end of the game, Cirno will record the result as a sequence , where is the number of the bot that occupies the -th tower at the end of the game.
However, as a mathematics master, she wants you to solve the following counting problem instead of playing games:
Count the number of different pairs of sequences and that we can get from all possible choices of sequence and permutation .
Since this number may be large, output it modulo .
The only line contains two positive integers and (, ). It is guaranteed that is a divisor of and is a prime number.
You need to calculate the answer for .
Output a single integer — the number of different pairs of sequences for modulo .
No comments:
Post a Comment