Universal Cup Judging System

Universal Cup

Límite de tiempo: 4.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

给你一个正整数 $N$ 和一个质数 $P$。

对于 $1, 2, \dots, N$ 的一个排列 $(a_1, a_2, \dots, a_N)$,定义其得分 $f(a)$ 如下:

$$f(a) = \max\{i \cdot a_i \mid i = 1, 2, \dots, N\}$$

求所有排列的得分之和对 $P$ 取模后的结果。

输入格式

第一行包含 $N, P$,以空格分隔。($1 \le N \le 10^4$,$10^8 \le P < 10^9$,$P$ 是质数)

输出格式

输出所有排列的得分之和对 $P$ 取模后的结果。

样例

输入格式 1

10 100000007

输出格式 1

77379290

说明

对于第一个样例,例如 $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$。

输入格式 2

1000 998244353

输出格式 2

168695631

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1531EditorialOpen题解jiangly2026-04-15 16:05:22View

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.