#include <bits/stdc++.h>
using namespace std;
long long qpow(long long a, long long b, long long modp) {
  long long ans;
  for (ans = 1; b; b >>= 1, a = a * a % modp)
    if (b & 1) ans = ans * a % modp;
  return ans;
}
long long gcd(long long x, long long y) {
  while (y) {
    long long r = x % y;
    x = y;
    y = r;
  }
  return x;
}
void extgcd(long long a, long long b, long long &x, long long &y) {
  if (b != 0) {
    extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
}
long long mod_inv(long long a, long long modp) {
  long long x, y;
  extgcd(a, modp, x, y);
  return (modp + x % modp) % modp;
}
long long crt(long long a1, long long m1, long long a2, long long m2) {
  long long g = gcd(m1, m2);
  long long k = a1 % g;
  if (k != a2 % g) return -1;
  m1 /= g, m2 /= g;
  a1 /= g, a2 /= g;
  return ((a1 + m1 - a2 % m1) % m1 * mod_inv(m2 % m1, m1) % m1 * m2 + a2) %
             (m1 * m2) * g +
         k;
}
long long calc(long long x, long long m, long long d) {
  long long res = x / d;
  if (x % d >= m) ++res;
  return res;
}
int a;
int main() {
  int T = 1;
  for (int i = 0; i < 1000000; ++i) a += i;
  for (int cT = 1; cT <= T; ++cT) {
    long long a1, b1, a2, b2, L, R;
    cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
    L = max(L, b1);
    L = max(L, b2);
    b1 %= a1;
    b2 %= a2;
    if (b1 < 0) b1 += a1;
    if (b2 < 0) b2 += a2;
    long long g = gcd(a1, a2);
    if (b1 % g != b2 % g || L > R) {
      cout << 0 << endl;
      continue;
    }
    long long k = crt(b1, a1, b2, a2);
    L -= k, R -= k;
    k = 0;
    if (L < 0 && R < 0) L = -L, R = -R, swap(L, R);
    long long ans;
    if (L >= 0 && R >= 0)
      ans = calc(R, k, a1 * a2 / g) - calc(L - 1, k, a1 * a2 / g);
    else
      ans = max(calc(R, k, a1 * a2 / g) + calc(-L, k, a1 * a2 / g) +
                    (k == 0 ? -1 : 0),
                0LL);
    cout << ans << endl;
  }
  return 0;
}
