#include<bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define pb push_back
#define FR first
#define SC second
#define MOD 1000000007
#define LLMN LLONG_MIN
#define LLMX LLONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000010
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vl >
#define vb vector<bool>
#define vbb vector< vb >
#define vpl vector<pll>
#define vpll vector< vpl >

void solve()
{
    ll x, y, a, b;
    cin>>x>>y>>a>>b;
    ll ans = 0;
    while(1)
    {
        if(x > y / a)
            break;
        if(a * x >= y)
            break;
        if(a * x > x + b)
            break;
        x *= a;
        ans++;
    }
    ans += (y - x - 1) / b;
    cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
#include <cstdlib>
#include <math.h>
#include <string>
#include <time.h>
using ld = long double;
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main() {
    //始点(r1, c1)、終点(r2, c2)
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    int r = r2 - r1;
    int c = c2 - c1;

    int ans = 3;
    // absは絶対値
    if (!r && !c) {
        ans = 0;
    } else if (r == c || r == -c || abs(r) + abs(c) <= 3) {
        ans = 1;
    } else if ((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 ||
               abs(r) + abs(c) <= 6) {
        ans = 2;
    }
    cout << ans << endl;
}
