#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int p, q, r;
int a, b, c;
ll lo, hi;
vector<ll> sol;
ll cnt;
int potez;
int ee(int pr, int dr) {
    if(dr == 0) return pr;
    return ee(dr, pr%dr);
}
int main() {
    IOS; cin>>p>>q>>r>>lo>>hi;
    if(p*q*r-p*q-q*r-r*p<=0) {cout << 0; return 0;}
    a=p; b=q; c=r;
    int nzs=p*q*r/ee(ee(p,q),r);
    while(true) {
        double tren = (3*p*q*r-a*q*r-b*r*p-c*p*q)/(p*q*r-p*q-q*r-r*p) * 1LL;
        ll hocu=(ll)(ceil(tren));
        if((ll)potez!=hocu%(ll)nzs) {
            hocu+=-hocu%(ll)nzs+(ll)nzs+(ll)potez;
            if(hocu-(ll)nzs>=(ll)(ceil(tren))) hocu-=(ll)nzs;
        }
        sol.push_back(hocu);
        a=(a+1)%p; b=(b+1)%q; c=(c+1)%r;
        if(a==b && b==c && c==0) break;
        if(a==0) a=p;
        if(b==0) b=q;
        if(c==0) c=r;
        ++potez;
    }
    for(int i=0; i<nzs; ++i) {
        ll l=max(lo, sol[i]);
        ll duz=hi-l+1;
        if(duz<=0) continue;
        cnt += duz/(ll)nzs;
        ll ostL = l%(ll)nzs;
        ll ost = duz%(ll)nzs;
        ll ostSol = sol[i]%(ll)nzs;
        if((ostSol>=ostL&&ostSol<=ostL+ost-1)||(ostSol+nzs>=ostL&&ostSol+nzs<=ostL+ost-1)) ++cnt;
    }
    cout << cnt;
    return 0;
}