ChocoLove

0

0 votes
Easy
Problem

Aurora fest includes a number of cultural, technical and managerial events. For the proper and smooth functioning of the fest, each event is given an experienced organiser. Daksh is one of the most experienced and respected organiser of an event called ChocoLove for 5 years in a row.

For organising the event ChocoLove, Daksh is given 'N' chocolates and 'P' buckets. He has to distribute all the chocolates in the given buckets in such a manner that all the buckets have same number of chocolates (even if all the buckets are empty). In one time stamp, Daksh can do any one of the following operation :

  1. Find one more chocolate.
  2. Eat one chocolate.
  3. Find one more bucket.
  4. If there are at least two buckets merge them into one.

Can you help Daksh in finding the minimum number of time stamps needed such that all the buckets can have equal no. of chocolates.

Input :

  • Single line containing two space separated integers N and P i.e. no. of choclates and no. of buckets.

Output :

  • Single line containing the minimum number of time stamps needed.

Constraints :

  • 1<=N<=105
  • 1<=P<=105
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Think ... !! ;)

Editor Image

?