#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, l, r;
long long extended_euclid(long long a, long long b, long long &x,
                          long long &y) {
  long long xx = y = 0LL;
  long long yy = x = 1LL;
  while (b) {
    long long q = a / b;
    long long t = b;
    b = a % b;
    a = t;
    t = xx;
    xx = x - q * xx;
    x = t;
    t = yy;
    yy = y - q * yy;
    y = t;
  }
  return a;
}
long long solve(long double X, long double Y, long long &a, long long &b,
                long long &x, long long &y, long long &d) {
  if (X < 0 || Y < 0) return 0;
  long double L = 0, R = 0;
  long double r1 = 0, r2 = X;
  r1 -= x;
  r2 -= x;
  r1 *= d;
  r2 *= d;
  if (d < 0) swap(r1, r2);
  r1 /= b;
  r2 /= b;
  if (b < 0) swap(r1, r2);
  long double c1 = 0, c2 = Y;
  c1 -= y;
  c2 -= y;
  c1 *= -1.0;
  c2 *= -1.0;
  swap(c1, c2);
  c1 *= d;
  c2 *= d;
  if (d < 0) swap(c1, c2);
  c1 /= a;
  c2 /= a;
  if (a < 0) swap(c1, c2);
  r1 = ceil(r1);
  r2 = floor(r2);
  c1 = ceil(c1);
  c2 = floor(c2);
  if (r2 < r1) return 0;
  if (c2 < c1) return 0;
  if (c1 > r2 || c2 < r1) return 0;
  if (c1 >= r1 && c2 <= r2) return c2 - c1 + 1;
  if (r1 >= c1 && r2 <= c2) return r2 - r1 + 1;
  if (r1 <= c1 && c1 <= r2) return r2 - c1 - 1;
  if (c1 <= r1 && r1 <= c2) return c2 - c1 - 1;
  return 0;
}
int main() {
  scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &a1, &b1, &a2, &b2, &l, &r);
  long long a = a1, b = -a2, c = b2 - b1, x, y;
  long long d = extended_euclid(a, b, x, y);
  if (c % d) {
    printf("0\n");
    return 0;
  }
  x = (c / d) * x;
  y = (c / d) * y;
  long double A, B, C, D;
  A = (long double)(r - b1) / (long double)a1;
  B = (long double)(r - b2) / (long double)a2;
  C = (long double)(l - 1 - b1) / (long double)a1;
  D = (long double)(l - 1 - b2) / (long double)a2;
  printf("%I64d\n",
         max(0LL, solve(A, B, a, b, x, y, d) - solve(C, D, a, b, x, y, d)));
  return 0;
}
