Universal Cup Judging System

Universal Cup

Time Limit: 4.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Дано додатне ціле число $N$ і просте число $P$.

Для перестановки $(a_1, a_2, \cdots, a_N)$ чисел $1, 2, \cdots, N$ визначимо її оцінку $f(a)$ так.

$$f(a) = \max\{ia_i \mid i = 1, 2, \cdots, N\}$$

Знайдіть остачу від ділення суми оцінок за всіма перестановками на $P$.

Вхідні дані

Перший рядок містить $N, P$ у цьому порядку, розділені пробілами. ($1 \le N \le 10^4$, $10^8 \le P < 10^9$, $P$ — просте число)

Вихідні дані

Виведіть остачу від ділення суми оцінок за всіма перестановками на $P$.

Приклади

Приклад вхідних даних 1

10 100000007

Приклад вихідних даних 1

77379290

Приклад вхідних даних 2

1000 998244353

Приклад вихідних даних 2

168695631

Примітка

Для першого прикладу, зокрема, $f(3, 9, 4, 10, 8, 2, 7, 5, 6, 1) = 54$.

Сума оцінок за всіма $10!$ перестановками дорівнює $277379304$, а остача від ділення цього числа на просте число $P = 10^8 + 7$ дорівнює $77379290$, тому виведіть $77379290$. Зверніть увагу, що для цього вводу просте число $P$ є $9$-цифровим цілим числом $10^8 + 7$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1531EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.