#P6536. Minimum Cuts for Equal Sausage Distribution
Minimum Cuts for Equal Sausage Distribution
Minimum Cuts for Equal Sausage Distribution
You are given n sausages that need to be divided equally among m tasters. In other words, each taster should receive exactly n/m sausages in total.
To divide the sausages, you are allowed to make cuts. Each cut can split one sausage into exactly two pieces. Your goal is to achieve the equal distribution with as few cuts as possible.
Hint: It can be proven that the minimum number of cuts required is given by the formula:
$$\text{cuts} = m - \gcd(n, m)$$
Here, \(\gcd(n, m)\) represents the greatest common divisor of \(n\) and \(m\).
inputFormat
The input consists of a single line containing two positive integers n and m separated by a space.
\(1 \leq n, m \leq 10^9\)
outputFormat
Output a single integer, which is the minimum number of cuts required.
sample
3 3
0