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

Source: Internet
Author: User

Memory is now interested in the de-evolution of objects, specifically triangles. He starts with a equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral tria Ngle 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-degenerat E Triangle (triangle of positive area). At any moment of time, the length of each side should is integer.

What's the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input

The first and only line contains integers x and y (3≤y < x≤100)-the starting and ending equilateral Trian GLE side lengths respectively. Output

Print a single integer-the minimum number of seconds required for Memory to obtain the equilateral triangle of side Leng Th 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 A, B, and C as (A, B, c). Then, the Memory can do.

In the second sample test, Memory can does.

In the third sample test, Memory can does:

.


Test instructions: Give you a big equilateral triangle side length and a small equilateral triangle side length, each time you can change the length of an edge, but the request is still a triangle after each change, ask at least how many times you can turn the big triangle into a small triangle.


Analysis: The intuitive analysis of some difficulties, we consider the processing, the small size, each choice of small triangle of the smallest side of the larger, it is the largest change to the other side and minus one, so continue to iterate on it.


#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 100005
using 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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.