#include <bits/stdc++.h>
using namespace std;
const long long bound = (long long)4e9;
long long ext_gcd(long long a1, long long a2, long long &x1, long long &x2) {
  if (a2 == 0) {
    x1 = 1;
    x2 = 0;
    return a1;
  } else {
    long long y1, y2;
    long long g = ext_gcd(a2, a1 % a2, y1, y2);
    x1 = y2;
    x2 = y1 - a1 / a2 * y2;
    return g;
  }
}
int main() {
  long long a1, a2, b1, b2, L, R;
  long long x1, x2;
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  L = max(L, max(b1, b2));
  long long g = ext_gcd(a1, a2, x1, x2);
  if ((b2 - b1) % g) {
    cout << 0 << endl;
    return 0;
  }
  long long temp = (b2 - b1) / g;
  x1 *= temp;
  x2 *= temp;
  x2 = -x2;
  long long c1 = a2 / g, c2 = a1 / g;
  x1 = x1 - (x1 / c1) * c1;
  x2 = x2 - (x2 / c2) * c2;
  long long l = -bound, r = bound, x;
  long long c = a2 / g;
  while (l < r) {
    temp = (l + r + 1) / 2ll;
    x = (x1 + c * temp) * a1 + b1;
    if ((x <= R || x1 + c * temp < -bound) && x1 + c * temp <= bound)
      l = temp;
    else
      r = temp - 1;
  }
  x = (x1 + c * l) * a1 + b1;
  if (x < L)
    cout << 0 << endl;
  else
    cout << (x - L) / (c * a1) + 1ll << endl;
  return 0;
}
