CF#712 C. Memory and De-Evolution(水题)

来源:互联网 发布:java 自动生成代码 编辑:程序博客网 时间:2024/06/14 10:06
C. Memory and De-Evolution
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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 length 6 and wants one of side length 3. Denote a triangle with sides ab, 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的等边三角形,每次只能修改一条边且修改过程中三边始终能构成三角形,问至少修改几次?


思路:贪心加上逆向思维,把小三角形转变为大三角形,每次将最短的边修改为最长且合法的边。

#include<bits/stdc++.h>using namespace std;int main(){    int x,y;    while(scanf("%d%d",&x,&y)==2)    {        int sum=0;        int a1,a2,a3;        a1=a2=a3=y;        while(a1<x)        {            a1^=a2^=a1^=a2;            a2^=a3^=a2^=a3;            a3=a1+a2-1;            sum++;        }        printf("%d\n",sum);    }}




0 0