#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) return x = 1, y = 0, a;
  long long d = exgcd(b, a % b, x, y);
  long long t = x;
  x = y, y = t - a / b * y;
  return d;
}
long long a1, b1, a2, b2, L, R;
int main() {
  a1 = rd(), b1 = rd(), a2 = rd(), b2 = rd(), L = rd(), R = rd();
  long long x, y, d = exgcd(a1, -a2, x, y);
  if ((b2 - b1) % d) return puts("0"), 0;
  if (d < 0) y = -y, d = -d;
  (y *= ((b2 - b1) / d) % (a1 / d)) %= a1 / d;
  y = (y % (a1 / d) + (a1 / d)) % (a1 / d);
  x = (a2 * y + b2 - b1) / a1;
  if (x < 0) {
    x = (x % (a2 / d) + (a2 / d)) % (a2 / d);
    y = (a1 * x + b1 - b2) / a2;
  }
  L -= b2, R -= b2, L = max(L, 0ll);
  if (R < 0) return puts("0"), 0;
  L = (L > 0) ? (L - 1) / a2 + 1 : 0, R = R / a2;
  if (R < y) return puts("0"), 0;
  L -= y, R -= y, L = max(L, 0ll);
  R = R / (a1 / d) + 1, L = L ? (L - 1) / (a1 / d) + 1 : 0;
  rt(max(R - L, 0ll));
}
