#P6536. [COCI 2013/2014 #1] KUŠAČ
[COCI 2013/2014 #1] KUŠAČ
Background
Dun Dun invites you to evenly split sausages.
Problem Description
There are sausages, and they need to be evenly divided among tasters.
Each cut can split a sausage into two parts. You need to use as few cuts as possible to obtain sausages that meet the requirement. Find the minimum number of cuts needed.
Input Format
The input consists of one line with two positive integers and .
Output Format
Output one line with the minimum number of cuts.
2 6
4
3 4
3
6 2
0
Hint
Sample Explanation
Sample 1 Explanation
There are sausages and tasters. Cut each sausage into three equal parts, which takes cuts.
Sample 2 Explanation
There are sausages and tasters. Cut the sausages into pieces of size . The first three people each get , and the last person gets .
Constraints
For all test cases, it is guaranteed that .
Notes
This problem is translated from COCI2013-2014 CONTEST #1 T2 KUŠAČ.
Translated by ChatGPT 5