#include <bits/stdc++.h>
using namespace std;
const int __n = 1e3 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
template <typename T>
inline void read(T &__result) {
  T x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  __result = x * f;
}
inline void GETTIME() {
  printf("Time = %.3lf s\n", (double)clock() / CLOCKS_PER_SEC);
}
long long mul(long long a, long long b, long long m) {
  int ans = 0;
  while (b) {
    if (b & 1) ans = (ans + a) % m;
    a = (a + a) % m;
    b >>= 1;
  }
  return ans % m;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long gcd = exgcd(b, a % b, x, y), z;
  z = x;
  x = y;
  y = z - a / b * y;
  return gcd;
}
int main() {
  long long m1, m2, r1, r2, l, r, x, y, M;
  read(m1);
  read(r1);
  read(m2);
  read(r2);
  read(l);
  read(r);
  long long g = exgcd(m1, m2, x, y), c = (r2 - r1 % m2 + m2) % m2;
  if (c % g != 0) {
    cout << 0 << '\n';
    return 0;
  }
  x = x * (c / g) % (m2 / g);
  c = r1 + x * m1;
  M = m1 / g * m2;
  c = (c % M + M) % M;
  l = max(l, max(r1, r2));
  long long k1 = l / M, k2 = r / M;
  if ((k1 - 1) * M + c >= l && (k1 - 1) * M + c <= r)
    k1--;
  else if (k1 * M + c < l)
    k1++;
  if (k2 * M + c > r) k2--;
  cout << max(0ll, k2 - k1 + 1) << '\n';
}
