#P8181. Josephus Variant Summation
Josephus Variant Summation
Josephus Variant Summation
There are \( n \) people, labeled \( 1 \) to \( n \), sitting in a circle playing a variant of the Josephus game. They count cyclically from \( 1 \) to \( m \) with a single, continuously increasing counter. Unlike the classical Josephus problem, whenever a person takes a turn, if the number they recite is not equal to \( 1 \), they are immediately eliminated. Note that even if a person survives by calling \( 1 \) in one turn, they may be eliminated later if on a subsequent turn they do not recite \( 1 \). The process continues in circular order (with the counter never resetting) until only one person remains. If the surviving person originally had label \( x \), we denote this by \( J_m(n)=x \>.
Given three integers \( m, l, r \), your task is to compute the sum \( \sum_{i=l}^{r} J_m(i) \) modulo \( 998244353 \).
inputFormat
The input consists of a single line containing three integers ( m, l, r ), where ( m ) is the counting limit and ( l ) and ( r ) define the inclusive range of ( n ) values over which the sum is computed.
outputFormat
Output a single integer representing ( \sum_{i=l}^{r} J_m(i) ) modulo ( 998244353 ).
sample
3 2 5
10