#include <bits/stdc++.h>
const int oo = 2139063143;
const int N = 1010000;
const int P = 1000000007;
using namespace std;
inline void sc(long long &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
inline void pr(long long x) { print(x), putchar('\n'); }
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 t = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return t;
}
long long multi(long long x, long long y, long long mod) {
  long long tmp =
      (x * y - (long long)((long double)x / mod * y + 1.0e-8) * mod);
  return tmp < 0 ? tmp + mod : tmp;
}
long long a[5], m[5];
int main() {
  long long n = 2, ma = -oo;
  for (int i = 1; i <= n; i++)
    sc(m[i]), sc(a[i]), ma = max(ma, a[i]), a[i] = (a[i] % m[i] + m[i]) % m[i];
  long long ans = 0, M = 1;
  for (int i = 1; i <= n; i++) {
    long long k, sb, d = exgcd(M, m[i], k, sb);
    if ((a[i] - ans) % d != 0) {
      puts("0");
      return 0;
    }
    k *= (a[i] - ans) / d;
    long long mm = M;
    M *= m[i] / d;
    ans += multi(k, mm, M);
    ans = (ans % M + M) % M;
  }
  long long l, r;
  sc(l), sc(r);
  l = max(l, ma);
  if (r < l) {
    pr(0);
    return 0;
  }
  l -= ans, r -= ans;
  if (l < 0) {
    long long g = -(l / M - 1);
    l += g * M, r += g * M;
  }
  pr(r / M - l / M + (l % M == 0));
  return 0;
}
