#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 11;   const long long MOD = 1e18;   long long a[N], b[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long x, y, l, r;     cin >> x >> y >> l >> r;     vector<long long> v;     long long k = 1, kk = 1;     for (int i = 0; i <= 60; i++) {       a[i] = k;       b[i] = kk;       if (k != -1 && r / k >= x && k * x <= r)         k *= x;       else         k = -1;       if (kk != -1 && r / kk >= y && kk * y <= r)         kk *= y;       else         kk = -1;     }     for (int i = 0; i <= 60; i++)       for (int j = 0; j <= 60; j++)         if (a[i] != -1 && b[j] != -1) {           long long dd = a[i] + b[j];           if (dd >= l && dd <= r) v.push_back(dd);         }     v.push_back(l - 1);     v.push_back(r + 1);     sort(v.begin(), v.end());     long long ans = 0;     for (int i = 1; i < v.size(); i++) ans = max(ans, v[i] - v[i - 1] - 1);     cout << ans << endl;   }   