#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
void fre() { freopen("input.in", "r", stdin); }
template <class T1, class T2>
inline void gmax(T1& a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1& a, T2 b) {
  if (b < a) a = b;
}
const int N = 200010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
long long a1, a2, b1, b2, L, R;
long long l, k, d, lcm;
void gcd(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long calc(long long top) {
  long long x = l * a2 + b2;
  if (top < x) return 0;
  return (top - x) / lcm + 1;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a1, &b1, &a2, &b2, &L, &R);
  gcd(a2, -a1, d, l, k);
  if ((b1 - b2) % d) {
    puts("0");
    return 0;
  }
  long long c = (b1 - b2) / d;
  l *= c, k *= c;
  if (d < 0) d = -d;
  lcm = a1 / d * a2;
  long long f = lcm / a2, g = lcm / a1;
  if (l < 0) {
    c = (-l - 1) / f + 1;
    l += c * f;
    k += c * g;
  }
  if (k < 0) {
    c = (-k - 1) / g + 1;
    l += c * f;
    k += c * g;
  }
  if (l - f >= 0 && k - g >= 0) {
    c = min(l / f, k / g);
    l -= c * f;
    k -= c * g;
  }
  printf("%I64d\n", calc(R) - calc(L - 1));
  return 0;
}
