#include <bits/stdc++.h>
//#include<iostream>
//#include<vector>
//#include<map> 
//#include<math.h>
//#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstring = vector<string>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) { return o << "{" << p.first << "," << p.second << "}"; }
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) { for(auto &v : vec) { is >> v; } return is; }
template<typename T> inline ostream& operator<<(ostream &os, vector<T> &vec) {
    //for(auto &v : vec) { os << v << ",";}
    for(auto &v : vec) { os << v << endl;}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline void chmax(T &a, T b) { a = max(a, b); }

ll x,y,a,b;

bool ok(ll n)
{
    ll d = y-x-1;
    if(d/n >= b) {
        return true;
    }
    if(x >= b) {
        return false;
    } else {
        ll x1 = x;
        while(n) {
            if(x1 * a> x+b) { break; }
            x1 *= a;
            n--;
        }
        if(n==0) { return false; }
        ll d1 = y-x1-1;
        if(d1/n >= b) {
            return true;
        } else {
            return false;
        }
    }
}

int main(void)
{
    cin >> x >> y >> a >> b;

    ll l = 0, r = LINF;

    while(r-l>1) {
        ll m = (r+l)/2;
        if(ok(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    
    cout << l << endl;
    return 0;
} /*atcoder*/

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll x, y, a, b;
	cin >> x >> y >> a >> b;

	ll ans = 0;
	while((double) a * x < 2e18 && a * x < y && a * x <= x + b){
		x *= a;
		ans++;
	}

	ans += (y - 1 - x) / b;
	cout << ans << endl;
}
