#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, L, R;
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return;
  }
  long long t;
  exgcd(b, a % b, x, y);
  t = x;
  x = y;
  y = t - (a / b) * y;
}
long long getinv(long long a, long long b) {
  long long x, y;
  exgcd(a, b, x, y);
  x = (x % b + b) % b;
  return x;
}
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
bool merge(long long &a1, long long &m1, long long a2, long long m2) {
  long long a3, m3, c, d, x;
  c = a2 - a1;
  d = gcd(m1, m2);
  if (c % d != 0) return false;
  c /= d;
  m1 /= d;
  m2 /= d;
  x = getinv(m1, m2);
  x = x * c % m2;
  x = (x * m1 * d) + a1;
  m3 = m1 * m2 * d;
  a3 = (x + m3) % m3;
  a1 = a3;
  m1 = m3;
  return true;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a1, &b1, &a2, &b2, &L, &R);
  L = max(L, max(b1, b2));
  b1 %= a1;
  b2 %= a2;
  if (merge(b1, a1, b2, a2) == false) {
    printf("0\n");
    return 0;
  }
  L -= b1;
  R -= b1;
  L--;
  if (L < 0 && L % a1 != 0) L -= (a1 - 1);
  if (R < 0 && R % a1 != 0) R -= (a1 - 1);
  R = (R / a1 - L / a1);
  R = max(R, 0LL);
  printf("%I64d\n", R);
  return 0;
}
