#P16342. [科大国创杯初中组 2026] 倍数调整

    ID: 18424 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>数学安徽枚举2026分类讨论科创活动初中活动科大国创杯

[科大国创杯初中组 2026] 倍数调整

Background

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

Problem Description

Xiaokeke has two positive integers a,ba, b.

One operation is defined as: choose one of aa and bb, and change it by +1+1 or 1-1. Note that you must always ensure a1a \ge 1 and b1b \ge 1.

Now Xiaokeke wants to make aa a multiple of bb using some number of operations. Please tell him the minimum number of operations needed.

Input Format

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

Output Format

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

9 6
2

Hint

Sample Explanation

You can do aa+1a \leftarrow a + 1 and bb1b \leftarrow b - 1. Then a=10a = 10 and b=5b = 5, which satisfies the condition. The number of operations is 22. 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:

  • 1a10181 \le a \le 10^{18},
  • 1b1061 \le b \le 10^6,
  • a,ba, b are both positive integers.
Test Point ID aa \le bb \le
121 \sim 2 101810^{18} 11
33 1010
454 \sim 5 40004000
676 \sim 7 10610^6 10610^6
8108 \sim 10 101810^{18}

Translated by ChatGPT 5