#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e2 + 10;
vector<long long> v1;
vector<long long> v2;
void add(vector<long long> &v, long long x) {
  long long o = 1;
  while (1) {
    v.push_back(o);
    if (o > INF * INF / x) break;
    o *= x;
  }
}
int main() {
  long long x, y, l, r;
  cin >> x >> y >> l >> r;
  add(v1, x);
  add(v2, y);
  vector<long long> v;
  for (auto &x : v1) {
    for (auto &y : v2) {
      if (x + y >= INF * INF) continue;
      v.push_back(x + y);
    }
  }
  long long pre = l;
  v.push_back(l - 1);
  v.push_back(r + 1);
  sort(v.begin(), v.end());
  long long ans = 0;
  for (auto &x : v) {
    if (x < l) continue;
    if (x > r) x = r + 1;
    ans = max(ans, x - pre);
    pre = x + 1;
  }
  cout << ans << endl;
  return 0;
}
