luogu#P4916. [MtOI2018] 魔力环
[MtOI2018] 魔力环
Background
wkr is an OIer from the City of Magic, and he likes collecting black and white magic beads.
Problem Description
wkr wants to obtain a ring made by stringing together magic beads. However, he is not interested in ordinary rings, so he proposes the following requirements:
- wkr wants the ring to have exactly black magic beads and white magic beads.
- Since wkr believes black magic beads should not be too dense, he wants that on the ring there will not appear a consecutive segment of black magic beads whose length exceeds .
In wkr’s mind, only rings that satisfy the above requirements are wonderful.
However, such rings may not be unique. wkr wants to know how many different rings satisfy his requirements. But wkr does not like doing calculations, so he hopes the smart you can tell him the answer.
Here, we consider two rings to be different if and only if one ring cannot be obtained from the other by rotation only.
Since the answer may be too large, output the result modulo .
Input Format
The input consists of line with non-negative integers , whose meanings are described above. Adjacent numbers are separated by a single space.
Output Format
Output line with integer, representing the number of rings that meet the requirements.
6 3 2
3
17 8 6
1421
50000 20000 1
683811528
Hint
Explanation of Sample
For rings made of magic beads, with exactly black magic beads and white magic beads, and with no consecutive segment of black magic beads of length greater than , there are different rings, as shown below.

The ring shown below does not meet wkr’s requirements, because in this ring there exists a consecutive segment of black magic beads whose length exceeds .

Subtasks
All testdata satisfy , , and .
This problem uses bundled tests. There are subtasks, and the score and limits of each subtask are as follows:
- Subtask 1 (3 points): .
- Subtask 2 (5 points): .
- Subtask 3 (8 points): .
- Subtask 4 (7 points): .
- Subtask 5 (19 points): .
- Subtask 6 (27 points): .
- Subtask 7 (31 points): No special restrictions.
Source
Problem setter: Imagine
72679
Translated by ChatGPT 5