#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;
int M = 2;
long long n, l, r, a0, m0, m[5], a[5];
long long ex_gcd(long long aa, long long bb, long long& xx, long long& yy) {
  if (bb == 0) {
    xx = 1, yy = 0;
    return aa;
  }
  long long dd = ex_gcd(bb, aa % bb, yy, xx);
  yy -= aa / bb * xx;
  return dd;
}
bool ModularLinearEquation(long long& m0, long long& a0, long long mm,
                           long long aa) {
  long long x, y, d;
  d = ex_gcd(m0, mm, x, y);
  if (labs(aa - a0) % d != 0) return false;
  mm /= d;
  x = x * (aa - a0) / d % mm;
  a0 += x * m0;
  m0 *= mm;
  a0 = (a0 % m0 + m0) % m0;
  return true;
}
bool CRT(long long& m0, long long& a0) {
  bool flag = true;
  m0 = 1, a0 = 0;
  for (int i = 0; i < M; i++) {
    if (ModularLinearEquation(m0, a0, m[i], a[i]) == false) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  while (scanf("%lld%lld%lld%lld%lld%lld", &m[0], &a[0], &m[1], &a[1], &l,
               &r) != EOF) {
    if (CRT(m0, a0) == false)
      printf("0\n");
    else {
      long long st, ed;
      st = l / m0 * m0 - m0 + a0;
      while (st < l) st += m0;
      ed = r / m0 * m0 + m0 + a0;
      while (ed > r) ed -= m0;
      st = max(st, max(a[0], a[1]));
      if (st > ed)
        printf("0\n");
      else
        printf("%lld\n", (ed - st) / m0 + 1);
    }
  }
  return 0;
}
