Score : $300$ points
You are given an integer $X$. The following action on this integer is called an operation.
The terms in the arithmetic progression $S$ with $N$ terms whose initial term is $A$ and whose common difference is $D$ are called good numbers.
Consider performing zero or more operations to make $X$ a good number. Find the minimum number of operations required to do so.
Input is given from Standard Input in the following format:
$X$ $A$ $D$ $N$
Print the answer as an integer.
6 2 3 3
1
Since $A=2,D=3,N=3$, we have $S=(2,5,8)$.
You can subtract $1$ from $X$ once to make $X=6$ a good number.
It is impossible to make $X$ good in zero operations.
0 0 0 1
0
We might have $D=0$. Additionally, no operation might be required.
998244353 -10 -20 30
998244363
-555555555555555555 -1000000000000000000 1000000 1000000000000
444445