P16342 [USTC Guochuang Cup Junior 2026] Multiple Adjustment

Background

Subtask 0 uses unofficial testdata, and Subtask 1 uses official testdata.

Description

Xiaokeke has two positive integers $a, b$. One operation is defined as: choose one of $a$ and $b$, and change it by $+1$ or $-1$. Note that you must always ensure $a \ge 1$ and $b \ge 1$. Now Xiaokeke wants to make $a$ a multiple of $b$ using some number of operations. Please tell him the minimum number of operations needed.

Input Format

One line with two positive integers $a, b$.

Output Format

One line with one number, representing the minimum number of operations needed to make $a$ a multiple of $b$.

Explanation/Hint

#### Sample Explanation You can do $a \leftarrow a + 1$ and $b \leftarrow b - 1$. Then $a = 10$ and $b = 5$, which satisfies the condition. The number of operations is $2$. It can be proven that no smaller number of operations exists. #### Other Sample Notes * **Samples 2 to 6**: See `adjust/adjust*.in` and `adjust/adjust*.ans` in the contestant directory. #### Constraints For all data, it is guaranteed that: - $1 \le a \le 10^{18}$, - $1 \le b \le 10^6$, - $a, b$ are both positive integers. | Test Point ID | $a \le$ | $b \le$ | | :---: | :---: | :---: | | $1 \sim 2$ | $10^{18}$ | $1$ | | $3$ | $10$ | $10$ | | $4 \sim 5$ | $4000$ | $4000$ | | $6 \sim 7$ | $10^6$ | $10^6$ | | $8 \sim 10$ | $10^{18}$ | $10^6$ | Translated by ChatGPT 5