首页 > 其他分享 >Codeforces Round #370 (Div. 2)-C. Memory and De-Evolution

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

时间:2023-06-12 17:36:09浏览次数:41  
标签:Evolution triangle equilateral De Codeforces length ans Memory side


原题链接


C. Memory and De-Evolution



time limit per test



memory limit per test



input



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 

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

.In the second sample test, Memory can do 

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

.In the third sample test, Memory can do: 

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

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

.

反过来思考怎么把边长为y的等边三角形变为变为边长为x的等边三角形,每次执行这样的操作,把最小的边变为其他两条边长的和减一


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define maxn 100005
using namespace std;
typedef long long ll;

int main(){
	
	int x, y, ans = 0;
	
	scanf("%d%d", &x, &y);
	int a = y, b = y, c = y;
	while(a != x || b != x || c != x){
		if(a < x){
			a = b + c - 1;
			if(a > x)a = x;
			ans++;
		}
		if(b < x){
			b = a + c - 1;
			if(b > x)b = x;
			ans++;
		}
		if(c < x){
			c = a + b - 1;
			if(c > x)c = x;
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

标签:Evolution,triangle,equilateral,De,Codeforces,length,ans,Memory,side
From: https://blog.51cto.com/u_16158872/6464264

相关文章