/*#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")*/
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<"\n";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ld n, x, y, a, b;
ld str, res, cnt;

void MAIN(int tc){
    cin >> x >> y >> a >> b;
    ld mul = 1;
    res = floor((y - x)/b)- (fmod(y - x, b) == 0);
    for(ld k = 1; k <= 100; k++){
        mul *= a;
        ld nx = x * mul;
        if(nx >= y) {
            res = max(res, k - 1);
            break;
        }
        ld rem = floor((y - nx) / b) - (fmod(y - nx, b) == 0);
        res = max(res, k + rem);
    }
    deb1((ll)res);
}

int main(){
    ios:: sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed; cout<<setprecision(10);

    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}
/**
 *    Author:  Sanchit Sinha
 *    Created: 17.10.2020 16:38:47       
**/
#include "bits/stdc++.h"
using namespace std; 

#define ll unsigned long long 
ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}

int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll x,y,a,b;
        cin>>x>>y>>a>>b;
        ll ans=0;
        while(x<y){
                if(x>=y/a && x+a>=y) break;
                if(x>=y/a){
                        ll div=(y-1-x)/b;
                        ans+=max(div,0);
                        break; 
                }
                ll x1=x*a;
                ll x2=x+b;
                if(x1<=x2){
                        x*=a;
                        if(x<y)ans++;
                        else break;
                }
                else{
                        ll div=(y-1-x)/b;
                        ans+=max(div,0);
                        break;
                }
        }   
        cout<<ans<<"\n";
        return 0;       
}
