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

本文探讨了如何通过改变等边三角形的一条边来逐渐调整其大小的问题,目标是最少操作次数将大三角形转化为小三角形。采用逆向思维,即从小三角形开始逐步增大,每次操作都确保三角形的合法性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 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 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值