#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 nn sausages, and they need to be evenly divided among mm 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 nn and mm.

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 22 sausages and 66 tasters. Cut each sausage into three equal parts, which takes 44 cuts.

Sample 2 Explanation

There are 33 sausages and 44 tasters. Cut the sausages into pieces of size 34\tfrac{3}{4}. The first three people each get 34\tfrac{3}{4}, and the last person gets 3×143\times \tfrac{1}{4}.


Constraints

For all test cases, it is guaranteed that 1n,m1001\le n,m\le 100.


Notes

This problem is translated from COCI2013-2014 CONTEST #1 T2 KUŠAČ.

Translated by ChatGPT 5