codeforces 712C C. Memory and De-Evolution(贪心)

来源:互联网 发布:问卷调查数据分析 编辑:程序博客网 时间:2024/06/06 04:27

Description

Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side lengthx, and he wishes to perform operations to obtain an equilateral triangle of side lengthy.

In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.

What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side lengthy?

Input

The first and only line contains two integers x andy (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.

Output

Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side lengthy if he starts with the equilateral triangle of side lengthx.

Sample Input

Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6

Sample Output

Hint

In the first sample test, Memory starts with an equilateral triangle of side length6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do .

In the second sample test, Memory can do .

In the third sample test, Memory can do:

.


正着推把握不了度,而反着推比较简单


#include<iostream>#include<algorithm>using namespace std;int main(){int x,y;cin >> x >> y;int arr[6];arr[0]=y;arr[1]=y;arr[2]=y;int ans=0;while(1){sort(arr,arr+3);if(arr[1]+arr[2]>x){ arr[0] = x; ans++;}   else { arr[0] = arr[1]+arr[2]-1; ans++;}  if(arr[0]==arr[1]&&arr[1]==arr[2])    break;}cout << ans << endl;return 0;}


0 0
原创粉丝点击