#C7522. Watering Frequency
Watering Frequency
Watering Frequency
You are given four integers a, b, x, and d. A plant is watered on days forming an arithmetic sequence starting from day d with a common difference of x; that is, on days
\(d, \; d+x, \; d+2x, \; \dots\).
The task is to determine how many times the plant is watered between day a and day b (inclusive). In other words, count the number of values in the set \(\{d + kx \;|\; k \ge 0\}\) that fall within the closed interval \([a, b]\).
inputFormat
The input consists of four space-separated integers: a, b, x, and d, where
- a and b define the interval \([a, b]\) (with a ≤ b),
- x is the interval between watering days, and
- d is the first day the plant is watered.
outputFormat
Output a single integer representing the number of times the plant is watered on days in the interval \([a, b]\).
## sample5 20 4 1
4