#abc255c. C - ±1 Operation 1
C - ±1 Operation 1
Score : points
问题描述
给定一个整数 。以下对该整数的操作被称为 操作。
- 选择并执行以下任一操作:
- 将 加到 上。
- 从 中减去 。
在等差数列 中,具有 项且首项为 、公差为 的各项被称为 好数。
考虑通过执行零次或多次操作,使 变成一个好数。找出完成这一目标所需的最少操作次数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given an integer . The following action on this integer is called an operation.
- Choose and do one of the following.
- Add to .
- Subtract from .
The terms in the arithmetic progression with terms whose initial term is and whose common difference is are called good numbers. Consider performing zero or more operations to make a good number. Find the minimum number of operations required to do so.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
6 2 3 3
Sample Output 1
1
Since , we have . You can subtract from once to make a good number. It is impossible to make good in zero operations.
Sample Input 2
0 0 0 1
Sample Output 2
0
We might have . Additionally, no operation might be required.
Sample Input 3
998244353 -10 -20 30
Sample Output 3
998244363
Sample Input 4
-555555555555555555 -1000000000000000000 1000000 1000000000000
Sample Output 4
444445
update @ 2024/3/10 10:51:25