Codeforces Round #370 (Div. 2) C. Memory and De-Evolution

来源:互联网 发布:域名投资的秘密电子书 编辑:程序博客网 时间:2024/06/06 06:49

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.

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

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<string>#include<algorithm>#include<cstdlib>#include<cstdio>#include<set>#include<map>#include<vector>#include<cstring>#include<stack>#include<cmath>#include<queue>#include <unordered_map>#define INF 0x3f3f3f3f#define eps 1e-9  #define MOD 1000000007 #define MAXN 100005using namespace std;typedef long long ll;typedef pair<int,int> pii;int main(){int x,y;scanf("%d%d",&x,&y);int a[3] = {y,y,y},num = 0;while(a[0] != x){a[0] = min(a[1] + a[2] - 1,x);sort(a,a+3);num++;}cout<<num<<endl;}


0 0
原创粉丝点击