atcoder#ABC156F. [ABC156F] Modularness
[ABC156F] Modularness
Score : points
Problem Statement
We have a sequence of numbers: .
Process the following queries in order:
- The -th query contains three integers , , and . Let be the following sequence of numbers: [ \begin{aligned} a_j = \begin{cases} x_i & ( j = 0 ) \ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{aligned} ] Print the number of such that $(a_j \sim \textrm{mod} \sim m_i) < (a_{j + 1} \sim \textrm{mod} \sim m_i)$.
Here denotes the remainder of divided by , for two integers and .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines.
The -th line should contain the response to the -th query.
3 1
3 1 4
5 3 2
1
For the first query, the sequence {} will be .
- $(a_0 \sim \textrm{mod} \sim 2) > (a_1 \sim \textrm{mod} \sim 2)$
- $(a_1 \sim \textrm{mod} \sim 2) < (a_2 \sim \textrm{mod} \sim 2)$
- $(a_2 \sim \textrm{mod} \sim 2) = (a_3 \sim \textrm{mod} \sim 2)$
- $(a_3 \sim \textrm{mod} \sim 2) > (a_4 \sim \textrm{mod} \sim 2)$
Thus, the response to this query should be .
7 3
27 18 28 18 28 46 1000000000
1000000000 1 7
1000000000 2 10
1000000000 3 12
224489796
214285714
559523809