|
||||||||||
Naughty fairiesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2002 Accepted Submission(s): 302 Problem Description Once upon a time, there lived a kind of fairy in the world. Those fairies could hear the voice of fruit trees, and helped people with a harvest. But people didn¡¯t know that fruits are also those fairies¡¯ favorite food. After the fairies ate people¡¯s fruits, they always did something to cover it up. One day a little fairy named Lily flew into an orchard and found a large peach tree. Hungry as Lily was, she started eating without thinking until her stomach was full. In the fairy world, when a fairy ate the fruits in a fruit tree, sometimes the fruit tree would feel honored and bore more fruits immediately. That¡¯s why sometimes the number of fruits in a tree got increased after a fairy ate fruits of that tree. But the fairies didn¡¯t want people to find out weird things such as fruits become more or less suddenly. Lily decided to use a magic spell so that the orchard owner couldn¡¯t find the change of the number of peaches. Suppose there were N peaches on a tree originally and there were M peaches left after Lily was full. M may be greater than, less than or equal to N. All M peaches were visible at first, and Lily wanted to make an illusion so that exactly N peaches are visible. Lily can do 3 kinds of spell to change the total visible number of peaches: 1) ¡°PAPADOLA¡±£ºThis spell would increase the number of visible peaches by one. 2) ¡°EXPETO POTRONUM¡±£ºThis spell would double the number of visible peaches. 3) ¡°SAVIDA LOHA¡±:This spell would decrease the number of visible peaches by one. Each spell would take one minute and Lily wanted to finish as fast as possible. Now please tell Lily the least time she needs to change the number of visible peaches to N. Input There are several test cases, ended by ¡°0 0¡±. For each test case, there are only one line containing two numbers separated by a blank, N and M, the original numbers of peaches and the numbers of peaches left(0<N,M<10500).There is no leading zero. Output For each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic. Sample Input
Sample Output
Source | ||||||||||
|