#include <bits/stdc++.h>
template <class T>
inline void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void read(T &x) {
  char c;
  int f = 1;
  x = 0;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    f = -1;
  else
    x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= f;
}
long long extgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long ret = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return ret;
}
long long ceil(long long u, long long v) {
  long long t = u / v;
  if (t * v < u) ++t;
  return t;
}
long long floor(long long u, long long v) {
  long long t = u / v;
  if (t * v > u) --t;
  return t;
}
long long fmm(long long a, long long b, long long mod) {
  long long ret = 0;
  while (b) {
    if (b & 1) (ret += a) %= mod;
    (a += a) %= mod, b >>= 1;
  }
  return ret;
}
int main() {
  long long a1, b1, a2, b2, L, R;
  read(a1), read(b1), read(a2), read(b2), read(L), read(R);
  if (b2 < b1) std::swap(a1, a2), std::swap(b1, b2);
  long long x, y, gcd = extgcd(a1, a2, x, y);
  if ((b2 - b1) % gcd)
    puts("0");
  else {
    long long t = (b2 - b1) / gcd;
    x *= t, y *= t;
    long long u = a1 * a2 / gcd, v = fmm((x % u + u) % u, a1, u) + b1;
    long long l = ceil(L - v, u), r = floor(R - v, u);
    chkmax(l, std::max(ceil(b1 - v, u), ceil(b2 - v, u)));
    if (l > r)
      puts("0");
    else
      std::cout << r - l + 1 << std::endl;
  }
  return 0;
}
