#include <bits/stdc++.h>

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int> n
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

string print(__int128_t x) {
  if (x == 0)
    return "0";
  bool neg = false;
  if (x < 0) {
    neg = true;
    x *= -1;
  }
  string ans;
  while (x) {
    ans += char(x % 10 + '0');
    x /= 10;
  }

  if (neg)
    ans += "-";
  reverse(all(ans));
  return ans;
}

// #define MULTIPLE_TEST_CASES
void solve() {
  int x, y, a, b;
  cin >> x >> y >> a >> b;

  auto check = [&](__int128_t mid) {
    __int128_t maxx = 0;
    for (__int128_t xo = x, exp = 0; xo < y; xo *= a, ++exp) {
      __int128_t expo = exp;
      expo += (y - 1 - xo) / b;
      maxx = max(maxx, expo);
    }
    return maxx;
  };

  cout << print(check(x)) << endl;
}

signed main() {
  // const string FILE_NAME = "";
  // freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
  // freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll x,y,a,b;cin >> x >> y >> a >> b;
    ll ans=0;
    if(x>=y/a)cout << ans+(y-1-x)/b <<endl,exit(0);
    while(true){
        if(x>=y/a)cout << ans+(y-1-x)/b <<endl,exit(0);
        if(x>=(x+b)/a)cout << ans+(y-1-x)/b <<endl,exit(0);
        else {
            ans++;
            x=x*a;
        }
    }
}

