COCI '25 Contest 5 #5 Struktura
View as PDF
Petar and Ivana are bored during a long winter afternoon, so they decided to invent a game with numbers.
Petar takes a sheet of paper and randomly writes down numbers. Each number is chosen completely at random and independently among the integers from
to
. Using this procedure, Petar creates an array
of
numbers.
Ivana says that she especially likes some arrays because they have a "hidden balance", and she calls them structures. An array is a structure if the following conditions are satisfied:
- Every number from
to
appears in the array exactly once.
- For every index
, it holds that
.
Ivana is interested in the probability that Petar, choosing the numbers completely at random, constructs an array that is a structure.
It can be proven that the answer can always be represented as a fraction , where
is an integer and
is a positive integer not divisible by
. In that case, output
.
Input Specification
The first line contains the natural numbers and
, the numbers from the problem statement.
Output Specification
Output a single number, the answer to the question from the problem statement.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| No additional constraints. |
Sample Input 1
2 1
Sample Output 1
0
Sample Input 2
2 2
Sample Output 2
500000004
Explanation for Sample Output 2
The arrays that Petar can construct are:
. The arrays that are structures are
and
. The probability that Petar completely at random obtains an array that is a structure is
, i.e.
.
Sample Input 3
7 94
Sample Output 3
100976822
Comments