Universal Cup Judging System

Universal Cup

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

正の整数 $N$ と素数 $P$ が与えられます。 $1, 2, \dots, N$ の順列 $(a_1, a_2, \dots, a_N)$ に対して、そのスコア $f(a)$ を以下のように定義します。

$$f(a) = \max\{i 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

入力 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题解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.