#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y, a, b; cin >> x >> y >> a >> b;
  ll tmp = 0;
  ll ans = 0;
  while(x < y) {
    chmax(ans, (y-x-1)/b+tmp);
    if(y/x < a) break;
    x *= a;
    tmp++;
  }
  cout << ans << endk;
  return 0;
}

#include <bits/stdc++.h>
typedef long int l;
typedef unsigned long int ul;
typedef long long int ll;
typedef unsigned long long int  ull;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define fs first
#define sd second
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1   e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
l gcd(l a, l b){return b?gcd(b,a%b):a;}
l lcm(l a, l b){return a/gcd(a,b)*b;}



void solve_test(){

      int a , b , x , y ;
      l answer ;
      cin >> a >> b >> x >> y ;

      if(a == b){

            cout << x <<endl ;
            return ;

      }

      if( a < b){
            answer = x + (b - a ) * y ;

            answer = min(answer , (l)(2 *(b-a) + 1) * x )  ;

            cout << answer << endl;
            return ;
      }

      if(a > b ){
            answer = x + ( a - b -1) * y ;
            answer = min(answer , (l)(2 *(a-b) -1) * x )  ;
            cout << answer << endl ;
            return ;
      }




}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    l test = 1 ;
    //cin>>test;
    while(test--){

        solve_test();


    }

    return 0 ;
}
