Memory and De-Evolution

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

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 length y?

Input

The first and only line contains two integers x and y (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 length y if he starts with the equilateral triangle of side length x.

Example
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 length 6 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:

.

题意:给出两个数X和Y,X代表修改之前的等边三角形的边长,Y代表修改之后的等边三角形的边长,要求在修改的过程中要保证是三角形(修改过程中可以不是等边三角形),每次只能修改一条边,修改的长度不限,问至少要修改几次才能边长为X修改成为边长为Y的等边三角形。

思路:反推法。

将边长有Y修改回X,在修改的过程中保证最长的边加第二长的边相加减一等于最短的边要修改为的长度,直到三条边都大于X即为修改完成。

设a,b,c为三边,切初始值都为Y,每次修改前都对边进行排序,按照a,b,c从小到大排列,之后修改最短的边长度为:a=b+c-1;

重复过程,直到a,b,c三边都大于X为止。

之前在做第一遍的时候是正着推的过程,每次修改最长边C=a+b+1;但是这样在最后快接近Y的时候特殊情况分类比较麻烦,考虑不全,部分数据会过不了,反推过程则是由三边都大于X截止循环重复,包含了所有特殊情况,简化了问题解决

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    int a[3];
    a[0]=a[1]=a[2]=y;
    int cnt=0;
    while(1)
    {
        sort(a,a+3);
        a[0]=a[1]+a[2]-1;
        cnt++;
        if(a[0]>=x&&a[1]>=x&&a[2]>=x)
            break;
    }
    printf("%d\n",cnt);
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值