#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool read(T& x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while ((c < '0' || c > '9') && (c != '-') && (c != EOF)) c = getchar();
  if (c == EOF) return 0;
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c & 15);
    c = getchar();
  }
  x *= f;
  return 1;
}
template <typename T, typename... Args>
inline bool read(T& x, Args&... args) {
  bool res = 1;
  res &= read(x);
  res &= read(args...);
  return res;
}
const double EPS = 1e-6;
const int M = 1000000007, INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int N = 1000010;
inline long long fp(long long a, long long b, long long Mod) {
  if (Mod == 1) return 0;
  long long res = 1;
  a %= Mod;
  for (; b; b >>= 1, a = a * a % Mod)
    if (b & 1) res = res * a % Mod;
  return res;
}
inline long long mul(long long a, long long b, long long p) {
  a %= p;
  b %= p;
  long long c = (long double)a * b / p;
  long long res = a * b - c * p;
  if (res < 0)
    res += p;
  else if (res >= p)
    res -= p;
  return res;
}
template <typename T>
inline T inv(T x, T P) {
  return (x == 1) ? 1 : ((P - P / x) * inv(P % x, P) % P);
}
template <typename T>
T gcd(T a, T b) {
  T t;
  while (b) {
    t = b;
    b = a % b;
    a = t;
  };
  return a;
}
template <typename T>
T exgcd(T a, T b, T& x, T& y) {
  T m = 0, n = 1, t;
  x = 1, y = 0;
  while (b) {
    t = m, m = x - a / b * m, x = t;
    t = n, n = y - a / b * n, y = t;
    t = b, b = a % b, a = t;
  }
  return a;
}
long long a1, b1, a2, b2, l, r;
inline void init() { read(a1, b1, a2, b2, l, r); }
inline long long Max(long long a, long long b) { return a < b ? b : a; }
inline long long Abs(long long a) { return a >= 0 ? a : -a; }
int fk = 0;
inline void solve() {
  long long u = 0, v = 0;
  l = Max(l, Max(b1, b2));
  if ((l == r) && (b1 == b2) && (l == b1)) {
    puts("1");
    return;
  }
  b1 %= a1;
  if (b1 < 0) b1 += a1;
  b2 %= a2;
  if (b2 < 0) b2 += a2;
  long long m = a1 / gcd(a1, a2) * a2;
  long long g = exgcd(a1, a2, u, v);
  long long t = b2 - b1;
  if (Abs(t) % g) {
    puts("0");
    return;
  }
  m = Abs(m);
  u *= (t / g);
  u %= m;
  long long ans = (mul(a1, u, m) + b1) % m;
  ans = (ans + m) % m;
  l += (m - ans);
  r += (m - ans);
  if (l > r) {
    puts("0");
    return;
  }
  if (l < 0) {
    long long d = (Abs(l) + 1) / m + 3;
    l += d * m;
    r += d * m;
  }
  l += m;
  r += m;
  printf("%lld\n", r / m - (l - 1) / m + fk);
}
signed main() {
  init();
  solve();
  return 0;
}
