#P4916. Necklace with Magic Beads
Necklace with Magic Beads
Necklace with Magic Beads
wkr wants a ring of n magic beads such that:
- There are exactly \( m \) black beads and \( n-m \) white beads.
- No contiguous (cyclic) segment of black beads has length greater than \( k \).
Two rings are considered identical if one can be obtained from the other by a rotation.
Your task is to count the number of distinct valid necklaces (rings) modulo \( 998\,244\,353 \).
Note: When checking the condition on consecutive black beads, consider the beads arranged in a circle (the sequence is cyclic).
inputFormat
The input consists of three integers n, m, and k separated by spaces.
outputFormat
Output a single integer: the number of distinct valid necklaces modulo \( 998\,244\,353 \).
sample
4 2 1
1