F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Naughty fairies

Time 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
5 2 1 99 86 32 0 0
 

Sample Output
2 98 12
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 08:48:55, Gzip enabled