#include<bits/stdc++.h>
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ld, ld> ptd;
typedef unsigned long long uli;

#define SORT(vec) sort(vec.begin(), vec.end())
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ft first
#define sc second
#define sz(a) int((a).size())
#define x first
#define y second


const int INF = int(1e9);
const li INF64 = li(INF) * li(INF);
const ld EPS = 1e-9;
const ld PI = ld(3.1415926535897932384626433832795);
int main(){
li x,y,a,b;
cin>>x>>y>>a>>b;
li ans=1;
li res=0;
for(int i=0;i<=60;i++){
	if(i!=0){
		ans*=a;
		
	}
	li num=ans*x;
	if(y<=num)break;
	if(num<(ans/a)*x)break;
	res=max(res,(i+(y-num-1)/b));
	
}
cout<<res<<"\n";
return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("file.txt","r",stdin );
#define outF freopen("perimeter.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define lp(i , n) for(int x = i ; x < n ; x ++)
#define ll long long
#define read(arr , x , n) for(int i = x ; i < n ; i ++ )cin >> arr[i];
#define vector deque

const int N = 2e4 + 6, M = N * 4 ;
const ll MOD = 1e9 + 7 ;

int32_t main()
{
    // inF;outF;
    fastio;
    // Dont Forget memset
    //inF;
    ll ans = 0 , a , b , c , d;
    cin >> a >> b >> c >> d ;

    while(b / c > a && a * c < a + d )ans ++ , a *= c ;

    b -= a ;
    b -- ;

    ans += b / d ;

    cout << ans ;
}
