GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 2 August 2022

[Solution] Game of AI (easy version) Codeforces Solution



H1. Game of AI (easy version)
time limit per test
2.5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This is the easy version of this problem. The difference between easy and hard versions is the constraint on k and the time limit. Also, in this version of the problem, you only need to calculate the answer when n=k. You can make hacks only if both versions of the problem are solved.

Cirno is playing a war simulator game with n towers (numbered from 1 to n) and n bots (numbered from 1 to n). The i-th tower is initially occupied by the i-th bot for 1in.

Before the game, Cirno first chooses a permutation p=[p1,p2,,pn] of length n (A permutation of length n is an array of length n where each integer between 1 and n appears exactly once). After that, she can choose a sequence a=[a1,a2,,an] (1ain and aii for all 1in).

The game has n rounds of attacks. In the i-th round, if the pi-th bot is still in the game, it will begin its

Solution Click Below:-  👉CLICK HERE👈

👇👇👇👇👇

 attack, and as the result the api-th tower becomes occupied by the pi-th bot; the bot that previously occupied the api-th tower will no longer occupy it. If the pi-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 b=[b1,b2,,bn], where bi is the number of the bot that occupies the i-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 a and b that we can get from all possible choices of sequence a and permutation p.

Since this number may be large, output it modulo M.

Input

The only line contains two positive integers k and M (1k50002M109 ). It is guaranteed that 218 is a divisor of M1 and M is a prime number.

You need to calculate the answer for n=k.

Output

Output a single integer — the number of different pairs of sequences for n=k modulo M.

No comments:

Post a Comment