#include <bits/stdc++.h>
using namespace std;
long long beda;
struct lll {
  long long a, b, c;
} data[5];
long long fpb(long long a, long long b) { return (b ? fpb(b, a % b) : abs(a)); }
long long kali(long long a, long long b) {
  if (b < 2) return a * b;
  if (b % 2)
    return (kali(a, b - 1) + a) % beda;
  else {
    long long temp = kali(a, b / 2);
    return (temp + temp) % beda;
  }
}
long long bawah(long long n, long long awal, long long beda) {
  long long ret =
      beda * (long long)floor((long double)(n - awal) / beda) + awal;
  return ret;
}
long long atas(long long n, long long awal, long long beda) {
  long long ret = beda * (long long)ceil((long double)(n - awal) / beda) + awal;
  return ret;
}
int main() {
  long long a1, a2, b1, b2, l, r;
  scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a1, &b1, &a2, &b2, &l, &r);
  long long x = abs(a1), y = abs(a2), z = b2 - b1;
  long long temp = fpb(x, fpb(y, z));
  x /= temp;
  y /= temp;
  z /= temp;
  if (z % fpb(x, y) != 0)
    puts("0");
  else {
    data[0] = {x, 1, 0};
    data[1] = {y, 0, 1};
    if (x < y) {
      lll temp = data[0];
      data[0] = data[1];
      data[1] = temp;
    }
    while (data[1].a != 1) {
      long long pk = data[0].a / data[1].a;
      data[2] = {data[0].a - pk * data[1].a, data[0].b - pk * data[1].b,
                 data[0].c - pk * data[1].c};
      data[0] = data[1];
      data[1] = data[2];
    }
    beda = abs(a1 / fpb(a1, a2) * a2);
    long long awal =
        (kali(kali(z, data[1].b) * (a1 > 0 ? 1 : -1), a1) + b1) % beda;
    if (awal < 0) awal += beda;
    long long kanan = bawah(r, awal, beda);
    long long kiri = atas(l, awal, beda);
    long long bat1 = atas(b1, awal, beda), bat2 = atas(b2, awal, beda);
    kiri = max(kiri, max(bat1, bat2));
    long long ans = (double)(kanan - kiri) / beda + 1;
    if (ans < 0) ans = 0;
    printf("%I64d\n", ans);
  }
  return 0;
}
