//2*10^9
//9*10^18
// __int128_t 
#include<bits/stdc++.h>
using namespace std;

#define ull unsigned long long int
#define ll long long int

const ll M=1e9+7;

//to handle when remainder is -neg we add + M
//but when rem is +pos that time also we add so use %M
//so it will work for both
ll mod(ll n){
	return (n%M + M)%M;	
}
ll modAdd(ll a, ll b){
	return mod(mod(a)+mod(b));
}
ll modMul(ll a, ll b){
	return mod(mod(a)*mod(b));
}
ll modMinus(ll a, ll b){
	return mod(mod(a)-mod(b));
}
ll modpow(ll x, ll n) 
{ 
	if (n == 0) 
		return 1%M;
	if (n == 1)
		return x%M; 
	ll u = modpow(x,n/2); 
	u = modMul(u,u); 
	if (n%2) 
		u = modMul(u,x); 
	return u; 
}
ll gcd(ll a,ll b){
	if(b==0)
		return a;
	return gcd(b,a%b);
}
bool isPrime(ll n){
	int end = sqrt(n);
	for(int i=2;i<=end;i++)
		if(n%i==0)
			return false;
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    int t=1;
    //cin>>t;

    while(t--){
    	ull x,y;
    	int a,b;

    	cin>>x>>y>>a>>b;

    	ull ans=0;
        ull start=1;
        for(int i=0;i<=60;i++){
            ull exp=0;
            if(i!=0)
                start*=a;
            ull val=x*start;
            
            if(val>=y)
                break;
            if(val<((start/a)*x))
                break;

            exp+=i;

            val+=1;

            exp=exp+((y-val)/b);
            

            ans=max(ans,exp);
        }
    	cout<<ans<<"\n";
    }
    return 0;
}
/*                             
    Coming Soon
*/

#define _USE_MATH_DEFINES
#include <bits/stdc++.h> 
#include <cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<int,int> pi;
typedef uint64_t i64;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vector<ll>> v2ll;
const int MOD = 1e9+7;
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAIN int main(){FAST_IO;ll tc;cin>>tc;while(tc--){solver();}ret0;}
#define MAIN1 int main(){FAST_IO;solver();ret0;}
#define rep(i,b,e) for(__typeof(e)i=(b)-((b)>(e));i!=(e)-((b)>(e));i+=1-2*((b)>(e)))
#define repa(i,x)  for(auto i:x)
#define vin(x) for(auto &i:x){cin>>i;}
#define vin1(x) for(ll i=1;i<x.size();i++){cin>>x[i];}
#define dbg(x) for(auto i:x){cout<<i<<" ";}cout<<ENDL;
#define ENDL "\n"
#define VALL(a) a.begin(),a.end()
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define MP(a,b) make_pair(a,b)
#define ff first
#define ss second
#define ret0 return 0;
#define ret return;
#define ms(a,v) memset(a,v,sizeof(a));
#define pb(x) push_back(x)
/*----------------------------*/
ll intlog(double base, double x) {
    return (ll)((log(x) / log(base)));
}
void solver(){
    ll x,y,a,b;
    cin>>x>>y>>a>>b;
    ll ans=0;
    ll amx=intlog(a,y-x);
    if(b==1){
        cout<<y-x-1<<ENDL;
        ret;
    }

    for(int i=0;i<amx;i++){
        ll nb=y-((ll)(x*pow(a,i)));
        if(nb<0)
            break;
        if(nb%b==0)
            continue;
        ll nbb=(max(0ll,nb))/b;
       // cout<<nbb<<" "<<y-((ll)(x*pow(a,i)))<<" "<<i<<ENDL;
        ans=max(ans,i+nbb);
    }
    cout<<ans<<ENDL;
    ret;
}

MAIN1