#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a, x = 1, y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
long long inv(long long t, long long p) {
  long long d, x, y;
  exgcd(t, p, x, y, d);
  return d == 1 ? (x % p + p) % p : -1;
}
bool ut(long long a1, long long m1, long long a2, long long m2, long long &a3,
        long long &m3) {
  long long d = gcd(m1, m2);
  long long c = a2 - a1;
  if (c % d != 0) return false;
  m3 = m1 * m2 / d;
  long long x = inv(m1 / d, m2 / d);
  long long y = (c / d * x) % (m2 / d);
  a3 = y * m1 + a1;
  return true;
}
long long crt(long long len, long long *b, long long *a) {
  long long a1 = a[1], n1 = b[1];
  long long a2, n2;
  for (int i = 2; i <= len; i++) {
    long long aa, nn;
    a2 = a[i], n2 = b[i];
    if (!ut(a1, n1, a2, n2, aa, nn)) {
      return -1;
    }
    a1 = aa;
    n1 = nn;
  }
  return (a1 + n1) % n1;
}
int k;
long long a[10], b[10];
long long b1, b2;
long long l, r;
int main() {
  cin >> a[1] >> b[1] >> a[2] >> b[2] >> l >> r;
  if (r < b[1] || r < b[2]) {
    printf("0\n");
    return 0;
  }
  b1 = b[1], b2 = b[2];
  long long q = max(b[1], -b[1]) / a[1];
  if (b[1] < 0) {
    b[1] += q * a[1];
    while (b[1] < 0) b[1] += a[1];
  }
  q = max(b[2], -b[2]) / a[2];
  if (b[2] < 0) {
    b[2] += q * a[2];
    while (b[2] < 0) b[2] += a[2];
  }
  b[1] %= a[1];
  b[2] %= a[2];
  long long r1 = b1 - b[1];
  long long r2 = b2 - b[2];
  r1 = max(r1, r2);
  long long res = crt(2, a, b);
  if (res < 0) {
    printf("0\n");
    return 0;
  }
  long long x = a[1] * a[2] / gcd(a[1], a[2]);
  r2 = r1 / x;
  if (r2 * x < r1) r2++;
  res += r2 * x;
  while (res - x >= b1 && res - x >= b2) {
    res -= x;
  }
  l = max(l, res);
  long long L = l / x * x;
  L += res;
  L += (l - L) / x * x;
  while (L > l) L -= x;
  while (L < l) L += x;
  long long R = r / x * x;
  R += res;
  R += (r - R) / x * x;
  while (R < r) {
    R += x;
  }
  while (R > r) {
    R -= x;
  }
  long long ans = (R - L) / x + 1;
  ans = max(ans, 0ll);
  cout << ans << endl;
  return 0;
}
