#include <cstdio>
#define min(a, b) ((a) < (b) ? (a) : (b))
bool flag = false;
int a, b, c, d;
int bucketA = 0, bucketB = 0;
int cntfA = 0, cntfB = 0;
int main()
{
scanf("%d %d %d %d", &a, &b, &c, &d);
if (a == c && b == d)
{
printf("2");
return 0;
}
if (c == 0 && d == 0)
{
printf("0");
return 0;
}
while (true) {
if (bucketA == 0) {
bucketA = a;
cntfA++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
if (bucketB == b) {
bucketB = 0;
cntfA++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
if (bucketB + bucketA > b) {
bucketA = bucketA + bucketB - b;
bucketB = b;
cntfA++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
else {
bucketB += bucketA;
bucketA = 0;
cntfA++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
}
bucketA = 0, bucketB = 0;
while (true) {
if (bucketB == 0) {
bucketB = b;
cntfB++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
if (bucketA == a) {
bucketA = 0;
cntfB++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
if (bucketB + bucketA > a) {
bucketB = bucketA + bucketB - a;
bucketA = a;
cntfB++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
else {
bucketA += bucketB;
bucketB = 0;
cntfB++;
if (bucketA == a && bucketB == b)
break;
if (bucketA == c && bucketB == d) {
flag = true;
break;
}
}
}
cntfA = min(cntfA, cntfB);
if (!flag) cntfA = -1;
printf("%d\n", cntfA);
return 0;
}
댓글