#P15569. [COCI 2025/2026 #5] 结构 / Struktura
[COCI 2025/2026 #5] 结构 / Struktura
Background
The full score for this problem is .
Problem Description
Petar and Ivana felt bored on a long winter afternoon, so they invented a number game.
Petar randomly writes down numbers on paper. Each number is chosen independently and uniformly from to , forming an array .
Ivana says she especially likes some arrays because they have a kind of “hidden balance”. She calls such arrays structures (structure). The array is a structure if and only if the following conditions are satisfied:
- The integers each appear in the array exactly once.
- For every index (), we have .
Ivana wants to know: when Petar generates the array completely at random, what is the probability that it is a structure.
It can be proven that the answer can always be written as a fraction , where is an integer, and is a positive integer that is not divisible by .
Input Format
One line contains two non-negative integers ().
Output Format
Output one integer, representing the required probability modulo .
2 1
0
2 2
500000004
7 94
100976822
Hint
Sample Explanation
Explanation for Sample #2:
There are possible arrays Petar can write: . Among them, the structures are and . The probability is , so the output is .
Subtasks
| Subtask | Score | Limits |
|---|---|---|
| , | ||
| , | ||
| No additional limits |
Translated by ChatGPT 5