#include <bits/stdc++.h>
using namespace std;
long long int nod(long long int a, long long int b, long long int& x,
                  long long int& y) {
  long long int d = a;
  x = 1;
  y = 1;
  if (b != 0) {
    long long int x1, y1;
    d = nod(b, a % b, x1, y1);
    x = y1;
    y = (x1 - a / b * y1);
  }
  return d;
}
long long int solve_neq(long long int a, long long int b, long long int c,
                        bool less) {
  long long int c_b = c - b;
  long long int inc = 0;
  if (!less && c_b >= 0) {
    inc = a - 1;
  } else if (less && c_b < 0) {
    inc = 1 - a;
  }
  return (c_b + inc) / a;
}
int main() {
  long long int a1, b1, a2, b2, L, R;
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  long long int x0, y0, d;
  d = nod(a1, a2, x0, y0);
  if ((b2 - b1) % d) {
    cout << 0 << endl;
  } else {
    x0 *= (b2 - b1) / d;
    y0 *= (b2 - b1) / d;
    assert(a1 * x0 + a2 * y0 == b2 - b1);
    long long int d1 = a2 / d;
    long long int d2 = a1 / d;
    long long int kmin = (numeric_limits<long long int>::min)();
    long long int kmax = (numeric_limits<long long int>::max)();
    kmin = max(kmin, solve_neq(d1, x0, 0, false));
    kmin = max(kmin, solve_neq(d2, 0, y0, false));
    long long int s1 = solve_neq(a1, 0, L - b1, false);
    kmin = max(kmin, solve_neq(d1, x0, s1, false));
    long long int s2 = solve_neq(a1, 0, R - b1, true);
    kmax = min(kmax, solve_neq(d1, x0, s2, true));
    if (kmax < kmin)
      cout << 0 << endl;
    else
      cout << kmax - kmin + 1 << endl;
  }
  return 0;
}
