#include <bits/stdc++.h>
const int H = 201;
using ll = long long;
ll p[H], q[H];
ll Extended_euclid(ll a, ll b, ll &x, ll &y) {
  p[0] = 1, p[1] = 0, q[0] = 0, q[1] = 1;
  ll z, c, i = 2;
  while (b > 0) {
    z = a / b;
    p[i] = p[i - 2] - z * p[i - 1];
    q[i] = q[i - 2] - z * q[i - 1];
    c = a % b, a = b, b = c;
    i++;
  }
  x = p[i - 2], y = q[i - 2];
  return a;
}
ll mul(ll a, ll b, ll M) {
  ll res = 0, sgn = 1;
  if (b < 0) sgn = -1;
  while (b != 0) {
    if (b % 2 != 0) res += a;
    b = b / 2;
    a = (a + a) % M;
  }
  return sgn * res;
}
ll CrtSolver(ll s1, ll s2, ll c1, ll c2, ll &resc, ll &lcm) {
  ll ra, rb, g;
  c1 = c1 % s1, c2 = c2 % s2;
  if (c1 < 0) c1 += s1;
  if (c2 < 0) c2 += s2;
  g = Extended_euclid(s1, s2, ra, rb);
  lcm = (s1 * s2) / g;
  if ((c2 - c1) % g != 0) return -1;
  resc = mul(mul(s1, ra, lcm), (c2 - c1) / g, lcm) + c1;
  resc = resc % lcm;
  if (resc < 0) resc = resc + lcm;
  return 0;
}
int main() {
  ll a1, a2, b1, b2, l, r, exist, lc, x, imn, imx, res = 0;
  scanf("%lld %lld %lld %lld %lld %lld", &a1, &b1, &a2, &b2, &l, &r);
  exist = CrtSolver(a1, a2, b1, b2, x, lc);
  if (exist == -1) {
    printf("0\n");
    return 0;
  }
  ll var =
      ((((((b1) > (b2)) ? (b1) : (b2))) > (l)) ? ((((b1) > (b2)) ? (b1) : (b2)))
                                               : (l));
  imn = (var - x) / lc;
  if (var - x > 0 && (var - x) % lc != 0) imn++;
  imx = (r - x) / lc;
  if (r - x < 0 && (r - x) % lc != 0) imx--;
  if (imx < imn)
    res = 0;
  else
    res = imx - imn + 1;
  printf("%lld\n", res);
  return 0;
}
