def euc(a, b): #requires a>=b
    if a%b==0:
        return [b, 0, 1]
    else:
        t=euc(b, a%b)
        return [t[0], t[2], t[1]-t[2]*(a/b)]

stuff=raw_input().split()
a1=int(stuff[0])
b1=int(stuff[1])
a2=int(stuff[2])
b2=int(stuff[3])
L=int(stuff[4])
R=int(stuff[5])

if a1<a2: #make a1>=a2
    a1, a2=a2, a1
    b1, b2=b2, b1

L=max(b1, b2, L) #accounts for >=0 restriction

if L>R:
    print 0
elif a1*a2==0: #handling dumb zero cases
    if a1==0 and a2==0:
        if b1==b2 and L<=b1 and b1<=R:
            print 1
        else:
            print 0
    elif a1==0:
        if (b1-b2) % a2==0 and L<=b1 and b1<=R:
            print 1
        else:
            print 0
    elif a2==0:
        if (b2-b1) % a1==0 and L<=b2 and b2<=R:
            print 1
        else:
            print 0
else:
    l=euc(a1, a2)
    gcd=l[0]
    a1coeff=l[1]
    a2coeff=l[2]
    if (b1-b2)%gcd==0:
        #now we solve for (x-b1)/gcd and apply CRT, using Euc to speed up the process
        q=a1*(b2-b1)/gcd * a1coeff + b1
        p=a1*a2/gcd
        print (R-q)/p - (L-q-1)/p
    else:
        print 0

import sys

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

# ax+by=c
def extgcd(a, b, c):
    if b == 0: return c, 0
    x, y = extgcd(b, a % b, c)
    return y, x - a // b * y

def first_term(a1, b1, a2, b2):
    g = gcd(a1, a2)
    T = lcm(a1, a2)

    # s*a1+t*a2=b2-b1
    if (b2 - b1) % g != 0: return -(10 ** 100)
    x0 = extgcd(a1 // g, a2 // g, (b2 - b1) // g)[0] * a1 + b1 - T * 10 ** 30

    ok = 10 ** 60
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2
        val = x0 + T * mid
        k = (val - b1) // a1
        l = (val - b2) // a2

        if k >= 0 and l >= 0:
            ok = mid
        else:
            ng = mid

    return x0 + ok * T

def f(a0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if a0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
a0 = first_term(a1, b1, a2, b2)

if a0 == -(10 ** 100):
    print(0)
    sys.exit()

print(f(a0, T, R + 1) - f(a0, T, L))

def bezout(a,b) :              # retourne (g,u,v) tel que g = a*u + b*v et g = pgcd(a,b)
    if b == 0 : return (a,1,0)
    q = a // b
    r = a % b
    (g,u1,v1) = bezout(b,r)
    return (g,v1,u1-q*v1)      # joli algo :-)

a1,a2,b1,b2,L,R=[int(k) for k in raw_input().split(" ")]

g,q,r=bezout(a1,b1)

res=0
#ok c donc equivalent a a1,b1,a2-k,b2-k,L-k,R-k  si b1%g=b2%g=k sinon pas de sol
if a2%g==b2%g:
    k=a2%g
    L-=k
    R-=k
    res=1
#ok c donc equivalent a a1/g,b1/g,a2/g,b2/g,(L-k)/g,(R-k)/g
a1/=g
b1/=g
a2/=g
b2/=g
L/=g
R/=g

a2or=a2
b2or=b2
a2p=a2/a1
b2p=b2/b1
a2%=a1
b2%=b1
#note : on a garde le qr tq  qa1+rb1=1
#On veut  xa1-yb1=b2-a2
x=(q*(b2-a2))%b1
y=-(r*(b2-a2))%a1
assert (x*a1-y*b1)%(a1*b1)==(b2-a2)%(a1*b1)
#ok tous les k*a1b1 + (x+kb1)a1 + (y+ka1)*b1
#quel est le min k tel que x+kb1>=0
L=max(L,a2or,b2or)
L2=L+( (x*a1+a2)%(a1*b1) - L%(a1*b1))%(a1*b1)
print  res*max((R-L2)/(a1*b1)+1,0)

import sys
# Uz ma to pretekanie nebavi!!!

def gcd(a, b):
    if b == 0:
        return [a, 1, 0]
    c = a%b
    [g, x1, y1] = gcd(b, c)
    x = y1
    y = x1 - y1 * (a//b)
    return [g, x, y]

a1, b1, a2, b2, l, r = [int(i) for i in input().split(" ")]
if max(b1, b2) > r:
    print(0)
    sys.exit(0)

l = max(l, b1, b2)
[g, xg, yg] = gcd(a1, a2)
if (b2 - b1) % g == 0:
    xg *= (b2 - b1) // g
else:
    print(0)
    sys.exit(0)
lcm = (a1 * a2) // g
val = xg * a1 + b1
if val >= l:
    val -= (((val - l) // lcm) + 1) * lcm

print(((r - val) // lcm) - ((l - val - 1) // lcm))

import sys
from fractions import gcd
from math import sqrt,log
import time
from random import randint
import random
from sets import Set
# ---------- Number Theory -------------#
def primes_upto(maxn):
    maxn+=1
    A = [False]*(maxn/2+5)
    p = 3
    while p*p<maxn:
        if not A[p>>1]:
            for j in range(p*p,maxn,2*p):
                A[(j>>1)]=True
        p+=2
    ret = [2]
    for p in range(3,maxn,2):
        if not A[(p>>1)]:
            ret.append(p)
    return ret
st = time.time()
prime_list = primes_upto(1000000)
def factor_sieve(maxn):
    maxn+=1
    factor = [0]*maxn
    lim  = int(sqrt(maxn))
    for i in range(2,lim+2):
        if factor[i] == 0:
            for j in range(i*i,maxn,i):
                factor[j] = i
    return factor
factor_list = factor_sieve(100000)
def totient_sieve(maxn): #returns an array of totient function
    factor=[]
    if maxn<100000:
        factor = factor_list
    else:
        factor = factor_sieve(maxn)
    maxn+=1
    tot = [1]*maxn
    tot[0] = 0
    for i in range(2,maxn):
        if factor[i] == 0:
            tot[i] = i-1
            continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            tot[i] = tot[y]*x
        else:
            tot[i] = tot[y]*(x-1)
    return tot
def mobius_sieve(maxn):
    factor=[]
    if maxn<100000:
        factor = factor_list
    else:
        factor = factor_sieve(maxn)
    maxn+=1
    mu = [1]*maxn
    for i in range(2,maxn):
        if factor[i] == 0:
            mu[i]=-1
            continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            mu[i] = 0
        else:
            mu[i]=mu[x]*mu[y]
    return mu
def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n-1:
            return False
    return True # n  is definitely composite

def is_prime(n, _precision_for_huge_n=10):
    if n in _known_primes or n in (0, 1):
        return True
    for p in _known_primes:
        if n%p==0:
            return False
    d, s = n - 1, 0
    while not d % 2:
        d, s = d >> 1, s + 1
    # Returns exact according to http://primes.utm.edu/prove/prove2_3.html
    if n < 1373653:
        return not any(_try_composite(a, d, n, s) for a in (2, 3))
    if n < 25326001:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5))
    if n < 118670087467:
        if n == 3215031751:
            return False
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7))
    if n < 2152302898747:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11))
    if n < 3474749660383:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13))
    if n < 341550071728321:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
    return not any(_try_composite(a, d, n, s)
                   for a in _known_primes[:_precision_for_huge_n])

_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
def brent(N):#Fails for perfect squares,primes
        if N%2==0:
                return 2
        if N<100000:
            return factor_list[N]
        y,c,m = random.randint(1, N-1),random.randint(1, N-1),random.randint(1, N-1)
        g,r,q = 1,1,1
        while g==1:
                x = y
                for i in range(r):
                        y = ((y*y)%N+c)%N
                k = 0
                while (k<r and g==1):
                        ys = y
                        for i in range(min(m,r-k)):
                                y = ((y*y)%N+c)%N
                                q = q*(abs(x-y))%N
                        g = gcd(q,N)
                        k = k + m
                r = r*2
        if g==N:
                while True:
                        ys = ((ys*ys)%N+c)%N
                        g = gcd(abs(x-ys),N)
                        if g>1:
                                break

        return g
def floor_sqrt(n):
    x = max(0,int(sqrt(n))-1)
    while x*x<=n:
        x+=1
    return x-1
def prime_factors(n):# Returns all prime factors of n
    ret = Set()
    if n==1:
        return ret
    if is_prime(n):
        ret.add(n)
        return ret
    x = floor_sqrt(n)
    if x*x == n:
        return prime_factors(x)
    x = brent(n)
    n/=x
    while n%x == 0:
        n/=x
    r1 = prime_factors(x)
    r2 = prime_factors(n)
    for i in r1:
        ret.add(i)
    for i in r2:
        ret.add(i)
    return ret
def factorization(n):
    X = prime_factors(n)
    arr = []
    for i in X:
        arr.append(i)
    ret = {}
    for i in range(0,len(arr)):
        val = 0
        p = arr[i]
        while n%p == 0:
            val+=1
            n/=p
        ret[p] = val
    assert(n==1)
    return ret
def divisors(n):
    X = factorization(n)
    A=[1]
    for p in X:
        a = X[p]
        x=p**a
        z=len(A)
        B = A
        for i in range(0,z):
            val=A[i]
            mul = p
            for j in range(1,a+1):
                B.append(val*mul)
                mul*=p
        A = B
    return A
def ndiv(n):
    x = factorization(n)
    ret=1
    for i in x:
        ret*=x[i]+1
    return ret
def sorted_divisors(n):
    return sorted(divisors(n))
myp = {}
def primepi(n):#Finds pi(10**10) in 12 secs, pi(10**11) in 1 minute O(sqrt(n)) memory
    if n<=1:
        return 0
    if myp.has_key(n):
        return myp[n]
    myp.clear()
    lim=floor_sqrt(n)
    sm=[]
    la =[]
    for i in range(0,lim+1):
        sm.append(i-1)
        if i==0:
            la.append(0)
            continue
        la.append(n/i-1)
    for p in range(2,lim+1):
        if sm[p-1] == sm[p]:
            continue
        cnt_p = sm[p-1]
        q = p*p
        en = min(lim,n/q)
        for i in range(1,en+1):
            d = i*p
            if d<=lim:
                la[i]-=la[d]-cnt_p
            else:
                la[i]-=sm[n/d]-cnt_p
        for i in range(lim,q-1,-1):
            sm[i]-=sm[i/p]-cnt_p
    for i in range(1,lim+1):
        myp[i] = sm[i]
        myp[n/i] = la[i]
    return la[1]
cache={}
def phi(n): #totient(n)
    if n in cache:
        return cache[n]
    ret = n
    x = prime_factors(n)
    for p in x:
        ret*=p-1
        ret/=p
    cache[n] = ret
    return ret

def inv(x,a): #(x,a) = 1
    r = phi(a)-1
    ret= pow(x,r,a)
    return ret

def crt(A,B):# all elements of A are mutually coprime
    N = 1
    for i in range(0,len(A)):
        N*=A[i]
    ret = 0
    for i in range(0,len(A)):
        val = A[i]
        md = B[i]
        prod_rem = N/val
        ret+=md*(prod_rem*inv(prod_rem,val))
    ans= ret%N
    return ans
_store = {}
a1,b1,a2,b2,l,r = map(int,raw_input().split())
l = max(l,max(b1,b2))
if l > r:
    print 0
    sys.exit()
g = gcd(a1,a2)
if (b1%g + g)%g != (b2%g + g)%g:
    print 0
    sys.exit()
X = (a1*a2)/g
A1 = a1
A2 = a2
f1,f2 = factorization(a1),factorization(a2)
for p in f1:
    if p in f2:
        if f1[p] <= f2[p]:
            A1/=(p**f1[p])
        else:
            A2/=(p**f2[p])
assert(gcd(A1,A2)==1)
P,Q = [A1,A2],[(b1%A1 + A1)%A1, (b2%A2 + A2)%A2]
rem = crt(P,Q)
# number of numbers between l,r, which are rem modulo X
size = r-l
l = (l%X + X)%X + 10*X - rem
r = l+size
print(r/X- (l-1)/X)

from fractions import gcd
def egcd(a, b):
    if a == 0:
        return [0, 1]
    if b == 0:
        return [1, 0]
    p = egcd(b%a, a)
    x = p[0]; y = p[1]
    return [y-x*(b//a), x]

def solve(a1, m1, a2, m2):
    sol = egcd(m1, m2)
    m1x = m1 * sol[0]
    m2y = m2 * sol[1]
    return (m1x*a2+m2y*a1)

a1, b1, a2, b2, L, R = map(int, input().split(' '))
L -= b1; R -= b1; b2 -= b1; b1 = 0;
g = gcd(a1, a2)
L = max(L, max(b1, b2))
if (b2%g != 0 or L > R):
    print(0)
    quit()
rmod = a1 * a2 // g;
a1 //= g; b2 //= g; a2 //= g;
sol = solve(b1, a1, b2, a2);
mod = a1 * a2;
sol %= mod; sol *= g;
L -= sol; R -= sol;
if (L <= 0):
    lnew = L%rmod; R += lnew - L; L = lnew;
L += rmod; R += rmod;
print(R//rmod - (L-1)//rmod)

from fractions import gcd
a1,b1,a2,b2,l,r=map(int,raw_input().split())

if b1<l:
    b1=(b1-l)%a1+l
if b2<l:
    b2=(b2-l)%a2+l
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

g=gcd(a1,a2)
var=a1/g*a2
lst1=[]
lst2=[]
ks1=max(b1,b2)

m=min(1+r,var+ks1)
while b1!=b2 and m>b1:
    if b1<b2:
        b1=(b1-b2)%a1+b2
    else:
        b2=(b2-b1)%a2+b1
if(m>b1):
    print (1+(r-b1)/var)
else:
    print "0"

a1, b1, a2, b2, L, R = map(int, input().split())

def xgcd(a,b):
    prevx, x = 1, 0
    prevy, y = 0, 1
    while b:
        q = a // b
        x, prevx = prevx - q * x, x
        y, prevy = prevy - q * y, y
        a, b = b, a % b

    return a, prevx, prevy

g, x, y = xgcd(a1, -a2)

if (b2 - b1) // g < 0:
    g, x, y = -g, -x, -y

if abs(b2 - b1) % abs(g) > 0:
    print(0)
else:
    a2g, a1g = a2 // abs(g), a1 // abs(g)

    x *= (b2 - b1) // g
    y *= (b2 - b1) // g

    if x < 0:
        y += ((abs(x) + a2g - 1) // a2g) * a1g
        x += ((abs(x) + a2g - 1) // a2g) * a2g

    if y < 0:
        x += ((abs(y) + a1g - 1) // a1g) * a2g
        y += ((abs(y) + a1g - 1) // a1g) * a1g

    if x >= 0 and y >= 0:
        k = min(x // a2g, y // a1g)
        x -= k * a2g
        y -= k * a1g

    res = a1 * x + b1
    lcm = a1 * a2 // abs(g)

    L, R = max(0, L - res), R - res

    if R < 0:
        print(0)
    else:
        print(R // lcm - L // lcm + (L % lcm == 0))

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

def gcd(x,y):
    while y:
        x,y=y,x%y
    return x

def modpow(x,y,m):
    # (x**y) % m
    if y==0: return 1%m
    elif y==1: return x%m
    elif y&1: return (modpow((x*x)%m,y//2,m)*x)%m
    else: return modpow((x*x)%m,y//2,m)

def inv(x,m):
    # return the inverse of x, modulo m
    # use euler's theorem
    tot=m
    mt=m
    for i in xrange(2,mt):
        if i*i>mt: break
        if mt%i==0:
            tot//=i
            tot*=i-1
            while mt%i==0: mt//=i
    if mt>1:
        tot//=mt
        tot*=mt-1
    # totient(m) = tot
    return modpow(x%m,tot-1,m)

def crt(x1,m1,x2,m2):
    # chinese remainder theorem solver
    # clean up
    m1=abs(m1)
    m2=abs(m2)
    x1%=m1
    x2%=m2
    if m1>m2:
        m1,m2=m2,m1
        x1,x2=x2,x1
    # get out a factor
    t=gcd(m1,m2)
    offset=x1%t
    if x1%t != x2%t:
        print("Something went wrong with the no intersection step")
    x1//=t
    m1//=t
    x2//=t
    m2//=t
    # get important numbers
    # r1 is 1 mod m1 and 0 mod m2
    # r2 is 0 mod m1 and 1 mod m2
    r1=(m2*inv(m2,m1))%(m1*m2)
    r2=(m1*inv(m1,m2))%(m1*m2)
    # pretty much done
    return t*((x1*r1+x2*r2)%(m1*m2))+offset

# k',l'>=0 is the most annoying thing ever
a1,b1,a2,b2,l,r=map(int,input().split())

# bound l,r so nothing breaks
if a1>=0: l=max(l,b1)
if a1<=0: r=min(r,b1)
if a2>=0: l=max(l,b2)
if a2<=0: r=min(r,b2)

if l>r: print(0)
elif l==r:
    # special case
    ans=1
    if b1!=l and (a1==0 or (l-b1)%a1 or (l-b1)//a1<0): ans=0
    if b2!=l and (a2==0 or (l-b2)%a2 or (l-b2)//a2<0): ans=0
    print(ans)
elif (b1-b2)%gcd(a1,a2)!=0:
    # they don't intersect
    print(0)
else:
    # general case is the best case
    a3=abs((a1*a2)//gcd(a1,a2))
    b3=crt(b1,a1,b2,a2)
    # solve stuff easily now
    # python rounds down always
    l=(l-b3+a3-1)//a3
    r=(r-b3)//a3
    print(max(0,r-l+1))

def upw(a,b):
    if a>0: return (a+b-1)/b
    a=-a
    return -(a/b)
def dwn(a,b):
    if a>0:return a/b
    a=-a;
    return -( (a+b-1)/b )
def xgcd(a,b):
    if(b==0): return [a,1,0];
    g,x1,y1=xgcd(b,a%b)
    return [g,y1,x1-(a/b)*y1];

a1,b1,a2,b2,l,r=map(long,raw_input().split())
if b2<b1:
    a1,a2=a2,a1
    b1,b2=b2,b1

g,x,y=xgcd(a1,a2)
if (b2-b1)%g!=0: print(0)
else:
    x=x*( (b2-b1)/g )
    y=y*( (b2-b1)/g )
    li1=max(upw(-x*g,a2),upw(y*g,a1))
    li2=upw((l-a1*x-b1)*g,a1*a2)
    ls=dwn((r-a1*x-b1)*g,a1*a2)
    li=max(li1,li2)
    if li>ls: print(0)
    else: print(ls-li+1)

def nod(a, b):
    if b == 0:
        return a, 1, 0
    else:
        answer, x, y = nod(b, a % b)
        x1 = y
        y1 = x - (a // b) * y
        return answer, x1, y1

a1, b1, a2, b2, l, r = list(map(int, input().split()))
coeff = b1
b1, b2, l, r = b1 - coeff, b2 - coeff, max(l - coeff, 0), r - coeff
l = max(b2, l)
od, x1, y1 = nod(a1, -a2)
if b2 % od != 0 or l > r:
    print(0)
else:
    x1, y1 = x1 * (b2 // od), y1 * (b2 // od)
    result = x1 * a1
    raznitsa = a1 * a2 // nod(a1, a2)[0]
    otvet = 0
    if result < l:
        vsp = (l - result) // raznitsa
        if (l - result) % raznitsa != 0:
            vsp += 1
        result += vsp * raznitsa
    if result > r:
        vsp = (result - r) // raznitsa
        if (result - r) % raznitsa != 0:
            vsp += 1
        result -= vsp * raznitsa
    if result <= r and result >= l:
        otvet += 1
        otvet += abs(result - r) // raznitsa
        otvet += abs(result - l) // raznitsa
    print(otvet)
    # 3 * (- 54) + 81 =

def gcd(a, b):
    if (a == 0):
        return [0, 1, b];
    res = gcd(b%a, a);
    d = res[2]
    x1 = res[0]
    y1 = res[1]
    return [y1 - (b // a) * x1, x1, d];

def find_any_solution(a, b, c):
    res = gcd(abs(a), abs(b))
    g = res[2]
    x0 = res[0]
    y0 = res[1]
    if (c % g != 0):
        return [False, 0, 0, 0]
    x0 *= (c // g);
    y0 *= (c // g);
    if (a < 0):
        x0 = -x0;
    if (b < 0):
        y0 = -y0;
    return [True, x0, y0, g];
# print(map(int, raw_input().split()))
a1, b1, a2, b2, L, R = map(int, raw_input().split())
bo, l, r, g = find_any_solution(a1, a2, b2 - b1)
# print(bo, l, r)
if bo:
    aa = a1 * l + b1
    dd = (a1 * a2) // g
    bb = max(b1, b2)
    ll = (bb - aa + dd - 1) // dd
    aa = aa + dd * ll
    oo = max((L - aa + dd - 1) // dd, 0)
    op = (R - aa) // dd
    print(max(op - oo + 1, 0))
else:
    print(0)

import sys

def gcd(x,y):
    if y==0: return (x,1,0)
    k = x//y
    g,a,b = gcd(y,x%y)
    return (g,b,a-b*k)

read = lambda: (int(x) for x in sys.stdin.readline().split())
a1,b1,a2,b2,l,r = read()
l = max(l,b1,b2)
r = max(l,r+1)
g,x,y = gcd(a1,a2)
if (b1-b2)%g: print(0), exit(0)
a = a1*a2 // g
b = b1 + (b2-b1)//g * x * a1
b %= a
lk = l // a + (l%a > b)
rk = r // a + (r%a > b)
print(rk-lk)

#!/usr/bin/env	python
#-*-coding:utf-8 -*-
import math
a1,b1,a2,b2,l,r=map(int,input().split())
if b1<l:b1=(b1-l)%a1+l
if b2<l:b2=(b2-l)%a2+l
c=a1//math.gcd(a1,a2)*a2
m=min(1+r,c+max(b1,b2))
while b1!=b2 and m>b1:
	if b1<b2:b1=(b1-b2)%a1+b2
	else:b2=(b2-b1)%a2+b1
print((m>b1)*(1+(r-b1)//c))

MAXI = 2 * (10 ** 10)

def sign(x):
    return 1 if x >= 0 else -1

def cstyle_int(x):
    if x == 0:
        return 0
    s = 1 if x >= 0 else -1
    x = abs(x)
    return s * int(x)

def exgcd(a, b):
    if b == 0:
       return (a, 1, 0)
    (r, x, y) = exgcd(b, a % b)
    t = y
    y = x - (a / b) * y
    x = t
    return (r, x, y)

def solve(a1, b1, a2, b2, L, R):
    a, b, c = a2, b2 - b1, a1
    llx = sign(L - b1 + a1 - 1) * abs(L - b1 + a1 - 1) / a1
    rrx = sign(R - b1) * abs(R - b1) / a1

    if rrx < 0:
        return 0

    llx = max(llx, 0)
    rrx = max(rrx, 0)

    lly = sign(L - b2 + a2 - 1) * abs(L - b2 + a2 - 1) / a2
    rry = sign(R - b2) * abs(R - b2) / a2

    if rry < 0:
        return 0

    lly = max(lly, 0)
    rry = max(rry, 0)

    ll = c * llx - b
    rr = c * rrx - b

    ll = sign(ll + a - 1) * abs(ll + a - 1) / a
    rr = sign(rr) * abs(rr) / a

    ll = max(lly, ll)
    rr = min(rry, rr)
    #print rr, ll

    (r, w, v) = exgcd(a1, a2)
    w = -w

    if (b1 - b2) % r != 0:
        return 0
    else:
        base1 = (b1 - b2) / r * w * a1 + b1
        base2 = (b1 - b2) / r * v * a2 + b2
        assert base1 == base2
        base = base1

        lcm = a1 * a2 / r
        #print base, lcm
        #print '>>', ll, rr, (rr * a2 + b2), (ll * a2 + b2)
        base -= (base / lcm + 1) * lcm
        while base > 0:
            base -= lcm
        #print (rr * a2 + b2 - base) / lcm , (ll * a2 + b2 - 1 - base) / lcm
        ans = (rr * a2 + b2 - base) / lcm - (ll * a2 + b2 - 1 - base) / lcm
        return max(0, ans)

def brute_force(a1, b1, a2, b2, L, R):
    i = 0
    sa, sb = set(), set()
    while a1 * i + b1 <= R:
        if a1 * i + b1 >= L:
            sa.add(a1 * i + b1)
        i += 1

    i = 0
    while a2 * i + b2 <= R:
        if a2 * i + b2 >= L:
            sb.add(a2 * i + b2)
        i += 1
    return len(sa & sb)

def test(*args):
    assert solve(*args) == brute_force(*args)

assert solve(2, 4, 3, 0, 6, 17) == 2
assert solve(2, 0, 3, 3, 5, 21) == 3
assert solve(2, 0, 3, 3, 5, 21) == brute_force(2, 0, 3, 3, 5, 21)
test(4, 2, 4, 4, 8, 200)
test(9, 2, 4, 4, 8, 200)
test(9, -2, 4, 4, 8, 200)
test(9, -2, 4, 4, -100, 200)
test(1412412, -112312, 3123412, 12313, -100, 200)
test(1, 0, 1, 0, -100, 200)
test(1, 0, 1, 0, 1, 1)
test(2, 0, 1, 0, 1, 1)
test(3, 8, 6, 8, -6, 0)

'''
import random
for i in xrange(10000):
    a1 = random.randint(1, 10)
    a2 = random.randint(1, 10)
    b1 = random.randint(-10, 10)
    b2 = random.randint(-10, 10)
    L = random.randint(-10, 10)
    R = random.randint(-10, 10)
    L, R = min(L, R), max(L, R)
    print a1, b1, a2, b2, L, R
    test(a1, b1, a2, b2, L, R)

test(967, 339, 632, 339, -828, -275)

print 'OK'

'''

if __name__ == '__main__':
    (a1, b1, a2, b2, L, R) = map(int, raw_input().split())
    print solve(a1, b1, a2, b2, L, R)

import math

# g, x, y
def gcd(a, b) :
    if a == 0 :
        return [b, 0, 1]
    l = gcd(b % a, a)
    g, x1, y1 = [int(i) for i in l]
    x = y1 - (b // a) * x1
    y = x1
    return [g, x, y]

def my_ceil(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    return math.ceil(u / v)

def my_floor(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    return math.floor(u / v)

a1, b1, a2, b2, L, R = [int(i) for i in input().split()]
A = a1
B = -a2
C = b2 - b1
g, x0, y0 = [int(i) for i in gcd(abs(A), abs(B))]

if A < 0 : x0 *= -1
if B < 0 : y0 *= -1

if C % g != 0 :
    print(0)
    exit()

x0 *= C // g
y0 *= C // g

le = max([
    float(R - b1 - a1 * x0) / float(a1 * B // g),
    float(y0 * a2 + b2 - R) / float(a2 * A // g)
    ])

ri = min([
    float(L - b1 - a1 * x0) / float(a1 * B // g),
    float(y0 * a2 + b2 - L) / float(a2 * A // g),
    float(-x0) / float(B // g),
    float(y0) / float(A // g)
    ])

le = int(math.ceil(le))
ri = int(math.floor(ri))

if ri - le + 1 <= 10000 :
    result = 0
    for k in range(le - 100, ri + 101) :
        X = x0 + B * k // g
        Y = y0 - A * k // g
        if X >= 0 and Y >= 0 and a1 * X + b1 >= L and a1 * X + b1 <= R :
            result += 1
    print(result)
else :
    print(max(int(0), ri - le + 1))

from fractions import gcd
a1,b1,a2,b2,l,r=map(int,input().split())

if b1<l:
    b1=(b1-l)%a1+l
if b2<l:
    b2=(b2-l)%a2+l
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

g=gcd(a1,a2)
var=a1/g*a2
lst1=[]
lst2=[]
ks1=max(b1,b2)

m=min(1+r,var+ks1)
while b1!=b2 and m>b1:
    if b1<b2:
        b1=(b1-b2)%a1+b2
    else:
        b2=(b2-b1)%a2+b1
if(m>b1):
    print (int(1+(r-b1)//var))
else:
    print ("0")

def extgcd(a, b):
    x, y = 0, 0
    d = a;
    if b != 0:
        d, y, x = extgcd(b, a%b)
        y -= (a//b) * x
    else:
        x, y = 1, 0
    return (d, x, y)

def main():
    a1, b1, a2, b2, L, R = map(int, input().split())
    g, k, l = extgcd(a1, a2);
    b = b2-b1;
    if (b%g != 0):
        print (0)
        return
    k *= b//g
    l *= -b//g
    low = -2**100
    high = 2**100
    while high-low > 1:
        med = (low+high)//2
        tk = k+med*a2//g
        tl = l+med*a1//g
        if (tk >= 0 and tl >= 0):
            high = med
        else:
            low = med
    k = k+high*a2//g
    x = a1*k+b1
    low = -1
    high = 2**100
    lcm = a1*a2//g
    while high - low > 1:
        med = (low+high)//2
        tx = x+med*lcm
        if tx >= L:
            high = med
        else:
            low = med
    x = x+high*lcm
    low = 0
    high = 2**100
    while high-low > 1:
        med = (low+high)//2
        tx = x+med*lcm
        if (tx <= R):
            low = med
        else:
            high = med
    if low == 0 and x > R:
        print (0)
        return
    print (low+1)
    return

if __name__=="__main__":
    main()

import math
def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
#print("c",c,g)
if c%g != 0 :
 print (0)
 exit (0)
# ax-by = cc = bb-aa
# ax-by = g(cc) = bb-aa
#print(x,y)
i = a*(x*c)//g+aa
ii = (-b*(y*c)//g)+bb
#print(a*x//g*c,b*y//g*c,aa,bb)
step = a*b//g
#print(a,x,c , " | ",b,y,c)
#print(i,ii,step)
if (ii-i) % step != 0 :
 print(0)
 exit(0)
#print(a,x,c,aa)

#print(i,ii,step)
# shift i to la,lb
#print(i,aa,bb)
if i > max(aa,bb) :
 #print(i-max(aa,bb),step)
 i -= ((i-max(aa,bb))//step) * step
elif i < max(aa,bb) :
 i += ((max(aa,bb)-i)//step + (1 if (max(aa,bb)-i)%step!=0 else 0)) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

from collections import defaultdict
import sys, os, math

def gcd(a1, a2):
    if a2 == 0:
        return a1
    else:
        return gcd(a2, a1 % a2)

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)
if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a1, b1, a2, b2, L, R = map(int, input().split())
    a2 *= -1
    LCM = a1 * a2 // gcd(a1, a2)
    if abs(b1 - b2) % gcd(a1, a2) != 0:
        print(0)
        sys.exit(0)
    L = max([b1, b2, L])
    g, x, y = egcd(a1, a2)
    X = a1 * x * (b2 - b1) // g + b1
    X += LCM * math.ceil((L - X) / LCM)
    if L <= X <= R:
        print(max(0, (R - X) // LCM + 1))
    else:
        print(0)

#from IPython import embed

def xgcd(b, n):
    x0, x1, y0, y1 = 1, 0, 0, 1
    while n != 0:
        q, b, n = b // n, n, b % n
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return  b, x0, y0

def ffloor(a, b):
	if(b < 0): return ffloor(-a,-b);
	return a//b
def cceil( a,  b):
	if(b < 0): return cceil(-a,-b);
	if a % b == 0:
		return a//b
	return a//b+1;

def main():
	s = input()
	a1, b1, a2, b2, L, R = [int(i) for i in s.split()]

	if b2 < b1:
		a1, a2 , b1, b2 = a2, a1 , b2, b1

	d,x,y = xgcd(a1,-a2)#extended_gcd(a1,-a2)
	if(d < 0):
		d *= -1
		x *= -1
		y *= -1

	if (b2 - b1) % d !=  0:
		print(0)
		return

	#print(d,x,y)
	fact = (b2-b1)//d
	x *= fact
	y *= fact

	c1 = a2//d;
	c2 = a1//d;

	tope1 = ffloor(R-b1-a1*x, a1*c1);
	bajo1 = cceil(L-b1-a1*x,c1*a1);
	bajo2 = cceil(L-b2-a2*y,c2*a2);
	tope2 = ffloor(R-b2-a2*y, a2*c2);

	bajo3 = max(cceil(-x,c1),cceil(-y,c2));

	bajo = max(bajo1,bajo2,bajo3);
	tope = min(tope1,tope2);
	print(max(0,tope+1-bajo))
	#embed()
main()

#from IPython import embed
def mod(a, b):
	if b < 0:
		return mod(a,-b)
	if a >= 0:
		return a % b
	return - ((-a)%b)
def extended_gcd(a, b):
	tmp1 = a
	tmp2 = b
	xx = 0
	y = 0
	yy = 1
	x = 1
	while b != 0:
		q = a//b
		t = b
		b = mod(a,b)
		a = t
		tt = xx
		xx = x-q*xx
		x = t
		t = yy
		yy = y-q*yy
		y = t;
	assert(a == tmp1*x+tmp2*y)
	return (a,x,y)
def xgcd(b, n):
    x0, x1, y0, y1 = 1, 0, 0, 1
    while n != 0:
        q, b, n = b // n, n, b % n
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return  b, x0, y0

def ffloor(a, b):
	if(b < 0): return ffloor(-a,-b);
	return a//b
def cceil( a,  b):
	if(b < 0): return cceil(-a,-b);
	if a % b == 0:
		return a//b
	return a//b+1;

def main():
	s = input()
	a1, b1, a2, b2, L, R = [int(i) for i in s.split()]

	if b2 < b1:
		a1, a2 , b1, b2 = a2, a1 , b2, b1

	d,x,y = xgcd(a1,-a2)#extended_gcd(a1,-a2)
	if(d < 0):
		d *= -1
		x *= -1
		y *= -1

	if (b2 - b1) % d !=  0:
		print(0)
		return

	#print(d,x,y)
	fact = (b2-b1)//d
	x *= fact
	y *= fact

	c1 = a2//d;
	c2 = a1//d;

	tope1 = ffloor(R-b1-a1*x, a1*c1);
	bajo1 = cceil(L-b1-a1*x,c1*a1);
	bajo2 = cceil(L-b2-a2*y,c2*a2);
	tope2 = ffloor(R-b2-a2*y, a2*c2);

	bajo3 = max(cceil(-x,c1),cceil(-y,c2));

	#print((R-b1-a1*x) /( a1*c1) ,(R-b2-a2*y)/ (a2*c2))
	#print((L-b1-a1*x)/(c1*a1) ,(L-b2-a2*y)/(c2*a2))
	#print(-x/c1,-y/c2)
	#print(bajo1,tope1)

	#print(bajo2,tope2)
	#print(bajo3)
	bajo = max(bajo1,bajo2,bajo3);
	tope = min(tope1,tope2);
	print(max(0,tope+1-bajo))
	#embed()
main()

from math import gcd
def exd_gcd(a, b):
  # always return as POSITIVE presentation
  if a % b == 0:
    return 0, (1 if b > 0 else -1)
  x, y = exd_gcd(b, a % b)
  return y, x - a // b * y
def interval_intersect(a, b, c, d):
  if b <= a or d <= c:
    return 0
  if c < a:
    a, b, c, d = c, d, a, b
  if c < b:
    return min(b, d) - c
  else:
    return 0
def ceil(a, b):
  return (a + b - 1) // b

a1, b1, a2, b2, L, R = map(int, input().split())
g = gcd(a1, a2)
if (b1 - b2) % g != 0:
  print(0)
  exit(0)
k, l = exd_gcd(a1, a2)
l = -l
k *= (b2 - b1) // g
l *= (b2 - b1) // g
d1 = a2 // g
d2 = a1 // g
assert(k * a1 + b1 == l * a2 + b2)
arb = 3238
assert((k + arb * d1) * a1 + b1 == (l + arb * d2) * a2 + b2)
L1, R1 = ceil(max(0, ceil(L - b1, a1)) - k, d1), ((R - b1) // a1 - k) // d1
L2, R2 = ceil(max(0, ceil(L - b2, a2)) - l, d2), ((R - b2) // a2 - l) // d2
print(interval_intersect(L1, R1 + 1, L2, R2 + 1))

def exgcd(i, j):
    if j == 0:
        return 1, 0, i
    u, v, d = exgcd(j, i % j)
    return v, u - v * (i // j), d
ma, ra, mb, rb, L, R = map(int, input().split(' '))
L = max(L, ra, rb)
if L > R:
    print(0)
    exit(0)
if ra > rb:
    ma, ra, mb, rb = mb, rb, ma, ra
_, _, md = exgcd(ma, mb)
if md != 1:
    if (rb - ra) % md != 0:
        print(0)
        exit(0)
    m = ma * mb // md
    rev, _, _ = exgcd(ma // md, mb // md)
    rev = (rev % (mb // md) + mb // md) % (mb // md)
    r = ma * (rb - ra) // md * rev + ra
    r = (r % m + m) % m
else:
    m = ma * mb
    bv, av, _ = exgcd(ma, mb)
    r = ra * mb * av + rb * ma * bv
    r = (r % m + m) % m
def calc(i):
    return (i - r) // m
print(calc(R) - calc(L - 1))

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    #print(gg, X, Y, y, a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    if X >= 0:
        X -= (X//dd) * dd
    else:
        g = X//dd
        if g * dd > X:
            g += 1
        X -= g * dd

    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd

    if X > k:
        return 0
    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L-b1)//a1
if d1 < 0:
    d1 = 0
d1 *= a1
d1 += b1
d2 = (L-b2)//a2
if d2 < 0:
    d2 = 0
d2 *= a2
d2 += b2

while d1 < L:
    d1 += a1
while d2 < L:
    d2 += a2

#print(d1, d2, L, R)

if R < max(d1, d2):
    print(0)
else:

    if d1 > d2 or (d1 == d2 and a1 < a2):
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

def euc(a, b): #requires a>=b
    if a%b==0:
        return [b, 0, 1]
    else:
        t=euc(b, a%b)
        return [t[0], t[2], t[1]-t[2]*(a/b)]

stuff=raw_input().split()
a1=int(stuff[0])
b1=int(stuff[1])
a2=int(stuff[2])
b2=int(stuff[3])
L=int(stuff[4])
R=int(stuff[5])

if a1<a2: #make a1>=a2
    a1, a2=a2, a1
    b1, b2=b2, b1

L=max(b1, b2, L) #accounts for >=0 restriction

if L>R: #checking this once again
    print 0
elif a1*a2==0: #handling dumb zero cases
    if a1==0 and a2==0:
        if b1==b2 and L<=b1 and b1<=R:
            print 1
        else:
            print 0
    elif a1==0:
        if (b1-b2) % a2==0 and L<=b1 and b1<=R:
            print 1
        else:
            print 0
    elif a2==0:
        if (b2-b1) % a1==0 and L<=b2 and b2<=R:
            print 1
        else:
            print 0
else:
    l=euc(a1, a2)
    gcd=l[0]
    a1coeff=l[1]
    a2coeff=l[2]
    if (b1-b2)%gcd==0:
        #now we solve for (x-b1)/gcd and apply CRT, using Euc to speed up the process
        q=a1*(b2-b1)/gcd * a1coeff + b1
        p=a1*a2/gcd #solution for x is x=q (mod p), follows from a1coeff in gcd linear combination thing
        print (R-q)/p - (L-q-1)/p
    else:
        print 0

import sys
from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (int(a),int(1),int(0))
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return int(g),int(x),int(y)

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = int(a1)
B = int(a2)
C = int(b2 - b1)

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print(0)
    sys.exit(0)

X = int(X*C/G)
Y = int(Y*C/G)

K = int(max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] ))

# print("A",A,"B",B)
# print("G",G)
# print("X",X,"Y",Y)
# print("K",K)

# print("LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 ))
# print("UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 ))
# print("S", a1 * (X + B*K/G) + b1, "T", a2 * (-Y + A*K/G) + b2)

K = max( [ K, int(math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) )) ] )

U = math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) + 0.00001 )

# print(K,U)

while a1 * (X + B*K/G) + b1 < L:
    K = K + 1

# print(K, a1 * (X + B*K/G) + b1)

if K > U or a1 * (X + B*K/G) + b1 > R:
    ANS = 0;
else:
    ANS = U - K + 1

print(max( [ 0, int(ANS) ] ))

import sys, collections

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def extgcd(a, b):
    if b == 0: return 1, 0
    x, y = extgcd(b, a % b)
    return y, x - a // b * y

def prime_factor(n):
    res = collections.defaultdict(int)

    i = 2
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            n //= i
            cnt += 1
        if cnt > 0: res[i] = cnt
        i += 1
    if n != 1: res[n] = 1

    return res

def modinv(a, mod):
    if a == 0: return -1
    if gcd(a, mod) != 1: return -1
    return extgcd(a, mod)[0] % mod

def normalize(a1, a2):
    p1 = prime_factor(a1)
    p2 = prime_factor(a2)

    keys = list(set(p1.keys()) | set(p2.keys()))

    r1 = 1
    r2 = 1
    for k in keys:
        if p1[k] >= p2[k]:
            r1 *= k ** p1[k]
        else:
            r2 *= k ** p2[k]
    return r1, r2

def solve(a1, b1, a2, b2):
    g = gcd(a1, a2)
    if (b1 - b2) % g != 0: return -1

    a1, a2 = normalize(a1, a2)
    u = b1 % a1
    inv = modinv(a1, a2)
    v = (b2 - u) * inv % a2
    return u + v * a1

def f(x0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if x0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)

if x0 == -1:
    print(0)
    sys.exit()

x0 -= T * 10 ** 36

ok = 10 ** 60
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2

    val = x0 + T * mid
    k = (val - b1) // a1
    l = (val - b2) // a2
    if k >= 0 and l >= 0:
        ok = mid
    else:
        ng = mid

x0 += ok * T

# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)

print(ans)

a1, b1, a2, b2, L, R = map(int, input().split())

def xgcd(a,b):
    prevx, x = 1, 0
    prevy, y = 0, 1
    while b:
        q = a // b
        x, prevx = prevx - q * x, x
        y, prevy = prevy - q * y, y
        a, b = b, a % b

    return a, prevx, prevy

g, x, y = xgcd(a1, -a2)

if (b2 - b1) // g < 0:
    g, x, y = -g, -x, -y

if (b2 - b1) % g > 0:
    print(0)
else:
    a2g, a1g = a2 // abs(g), a1 // abs(g)

    x *= (b2 - b1) // g
    y *= (b2 - b1) // g

    if x < 0:
        y += ((abs(x) + a2g - 1) // a2g) * a1g
        x += ((abs(x) + a2g - 1) // a2g) * a2g

    if y < 0:
        x += ((abs(y) + a1g - 1) // a1g) * a2g
        y += ((abs(y) + a1g - 1) // a1g) * a1g

    if x >= 0 and y >= 0:
        k = min(x // a2g, y // a1g)
        x -= k * a2g
        y -= k * a1g

    res = a1 * x + b1
    lcm = a1 * a2 // abs(g)

    L, R = max(0, L - res), R - res

    if R < 0:
        print(0)
    else:
        print(R // lcm - L // lcm + (L % lcm == 0))

def nod(a, b):
    if b == 0:
        return a, 1, 0
    else:
        answer, x, y = nod(b, a % b)
        x1 = y
        y1 = x - (a // b) * y
        return answer, x1, y1

a1, b1, a2, b2, l, r = list(map(int, input().split()))
coeff = b1
b1, b2, l, r = b1 - coeff, b2 - coeff, l - coeff, r - coeff
od, x1, y1 = nod(a1, -a2)
if b2 % od != 0:
    print(0)
else:
    x1, y1 = x1 * (b2 // od), y1 * (b2 // od)
    result = x1 * a1
    raznitsa = a1 * a2 // nod(a1, a2)[0]
    otvet = 0
    if result < l:
        vsp = (l - result) // raznitsa
        if (l - result) % raznitsa != 0:
            vsp += 1
        result += vsp * raznitsa
    if result > r:
        vsp = (result - r) // raznitsa
        if (result - r) % raznitsa != 0:
            vsp -= 1
        result -= vsp * raznitsa
    if result <= r and result >= l:
        otvet += 1
        otvet += abs(result - r) // raznitsa
        otvet += abs(result - l) // raznitsa
    print(otvet)
    # 2x - 3y = 3

def nod(a, b):
    if b == 0:
        return a, 1, 0
    else:
        answer, x, y = nod(b, a % b)
        x1 = y
        y1 = x - (a // b) * y
        return answer, x1, y1

a1, b1, a2, b2, l, r = list(map(int, input().split()))
coeff = b1
b1, b2, l, r = b1 - coeff, b2 - coeff, max(l - coeff, 0), r - coeff
od, x1, y1 = nod(a1, -a2)
if b2 % od != 0 or l >= r:
    print(0)
else:
    x1, y1 = x1 * (b2 // od), y1 * (b2 // od)
    result = x1 * a1
    raznitsa = a1 * a2 // nod(a1, a2)[0]
    otvet = 0
    if result < l:
        vsp = (l - result) // raznitsa
        if (l - result) % raznitsa != 0:
            vsp += 1
        result += vsp * raznitsa
    if result > r:
        vsp = (result - r) // raznitsa
        if (result - r) % raznitsa != 0:
            vsp -= 1
        result -= vsp * raznitsa
    if result <= r and result >= l:
        otvet += 1
        otvet += abs(result - r) // raznitsa
        otvet += abs(result - l) // raznitsa
    print(otvet)
    # 3 * (- 54) + 81 =

def nod(a, b):
    if b == 0:
        return a, 1, 0
    else:
        answer, x, y = nod(b, a % b)
        x1 = y
        y1 = x - (a // b) * y
        return answer, x1, y1

a1, b1, a2, b2, l, r = list(map(int, input().split()))
coeff = b1
b1, b2, l, r = b1 - coeff, b2 - coeff, max(l - coeff, 0), r - coeff
l = max(b2, l)
od, x1, y1 = nod(a1, -a2)
if b2 % od != 0 or l > r:
    print(0)
else:
    x1, y1 = x1 * (b2 // od), y1 * (b2 // od)
    result = x1 * a1
    raznitsa = a1 * a2 // nod(a1, a2)[0]
    otvet = 0
    if result < l:
        vsp = (l - result) // raznitsa
        if (l - result) % raznitsa != 0:
            vsp += 1
        result += vsp * raznitsa
    if result > r:
        vsp = (result - r) // raznitsa
        if (result - r) % raznitsa != 0:
            vsp -= 1
        result -= vsp * raznitsa
    if result <= r and result >= l:
        otvet += 1
        otvet += abs(result - r) // raznitsa
        otvet += abs(result - l) // raznitsa
    print(otvet)
    # 3 * (- 54) + 81 =

def nod(a, b):
    if b == 0:
        return a, 1, 0
    else:
        answer, x, y = nod(b, a % b)
        x1 = y
        y1 = x - (a // b) * y
        return answer, x1, y1

a1, b1, a2, b2, l, r = list(map(int, input().split()))
coeff = b1
b1, b2, l, r = b1 - coeff, b2 - coeff, max(l - coeff, 0), r - coeff
l = max(b2, l)
od, x1, y1 = nod(a1, -a2)
if b2 % od != 0 or l >= r:
    print(0)
else:
    x1, y1 = x1 * (b2 // od), y1 * (b2 // od)
    result = x1 * a1
    raznitsa = a1 * a2 // nod(a1, a2)[0]
    otvet = 0
    if result < l:
        vsp = (l - result) // raznitsa
        if (l - result) % raznitsa != 0:
            vsp += 1
        result += vsp * raznitsa
    if result > r:
        vsp = (result - r) // raznitsa
        if (result - r) % raznitsa != 0:
            vsp -= 1
        result -= vsp * raznitsa
    if result <= r and result >= l:
        otvet += 1
        otvet += abs(result - r) // raznitsa
        otvet += abs(result - l) // raznitsa
    print(otvet)
    # 3 * (- 54) + 81 =

import sys

def gcd(x,y):
    if y==0: return (x,1,0)
    k = x//y
    g,a,b = gcd(y,x%y)
    return (g,b,a-b*k)

read = lambda: (int(x) for x in sys.stdin.readline().split())
a1,b1,a2,b2,l,r = read()
l = max(l,b1,b2)
r = max(l,r+1)
g,x,y = gcd(a1,a2)
a = a1*a2 // g
b = b1 + (b2-b1)//g * x * a1
b %= a
lk = l // a + (l%a > b)
rk = r // a + (r%a > b)
print(rk-lk)

import math

# g, x, y
def gcd(a, b) :
    if a == 0 :
        return [b, 0, 1]
    l = gcd(b % a, a)
    g, x1, y1 = [int(i) for i in l]
    x = y1 - (b // a) * x1
    y = x1
    return [g, x, y]

def my_ceil(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    return math.ceil(u / v)

def my_floor(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    return math.floor(u / v)

a1, b1, a2, b2, L, R = [int(i) for i in input().split()]
A = a1
B = -a2
C = b2 - b1
g, x0, y0 = [int(i) for i in gcd(abs(A), abs(B))]

if A < 0 : x0 *= -1
if B < 0 : y0 *= -1

if C % g != 0 :
    print(0)
    exit()

x0 *= C // g
y0 *= C // g

le = max([
    float(R - b1 - a1 * x0) / float(a1 * B // g),
    float(y0 * a2 + b2 - R) / float(a2 * A // g)
    ])

ri = min([
    float(L - b1 - a1 * x0) / float(a1 * B // g),
    float(y0 * a2 + b2 - L) / float(a2 * A // g),
    float(-x0) / float(B // g),
    float(y0) / float(A // g)
    ])

le = int(math.ceil(le))
ri = int(math.floor(ri))

print(max(0, ri - le + 1))

import math

# g, x, y
def gcd(a, b) :
    if a == 0 :
        return [b, 0, 1]
    l = gcd(b % a, a)
    g, x1, y1 = [int(i) for i in l]
    x = y1 - (b // a) * x1
    y = x1
    return [g, x, y]

def my_ceil(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    return math.ceil(u / v)

def my_floor(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    return math.floor(u / v)

a1, b1, a2, b2, L, R = [int(i) for i in input().split()]
A = a1
B = -a2
C = b2 - b1
g, x0, y0 = [int(i) for i in gcd(abs(A), abs(B))]

if A < 0 : x0 *= -1
if B < 0 : y0 *= -1

if C % g != 0 :
    print(0)
    exit()

x0 *= C // g
y0 *= C // g

le = max([
    float(R - b1 - a1 * x0) / float(a1 * B // g),
    float(y0 * a2 + b2 - R) / float(a2 * A // g)
    ])

ri = min([
    float(L - b1 - a1 * x0) / float(a1 * B // g),
    float(y0 * a2 + b2 - L) / float(a2 * A // g),
    float(-x0) / float(B // g),
    float(y0) / float(A // g)
    ])

le = int(math.ceil(le))
ri = int(math.floor(ri))

if ri - le + 1 <= 10000 :
    result = 0
    for k in range(le, ri + 1) :
        X = x0 + B * k // g
        if X >= 0 and a1 * X + b1 >= L and a1 * X + b1 <= R :
            result += 1
    print(result)
else :
    print(max(int(0), ri - le + 1))

import math

# g, x, y
def gcd(a, b) :
    if a == 0 :
        return [b, 0, 1]
    l = gcd(b % a, a)
    g, x1, y1 = [int(i) for i in l]
    x = y1 - (b // a) * x1
    y = x1
    return [g, x, y]

def my_ceil(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    if u >= 0 :
        if u % v != 0 :
            return int(u // v + 1)
        else :
            return int(u // v)
    else :
        return int(-((-u) // v))

def my_floor(u, v) :
    if v < 0 :
        u *= -1
        v *= -1
    if u >= 0 :
        return int(u // v)
    else :
        if (-u) % v != 0 :
            return int(-((-u) // v) - 1)
        else :
            return int(-((-u) // v))

a1, b1, a2, b2, L, R = [int(i) for i in input().split()]
A = a1
B = -a2
C = b2 - b1
g, x0, y0 = [int(i) for i in gcd(abs(A), abs(B))]

if A < 0 : x0 *= -1
if B < 0 : y0 *= -1

if C % g != 0 :
    print(0)
    exit()

x0 *= C // g
y0 *= C // g

le = max([
    my_ceil(R - b1 - a1 * x0, a1 * B / g),
    my_ceil(y0 * a2 + b2 - R, a2 * A / g)
    ])

ri = min([
    my_floor(L - b1 - a1 * x0, a1 * B / g),
    my_floor(y0 * a2 + b2 - L, a2 * A / g),
    my_floor(-x0, B / g),
    my_floor(y0, A / g)
    ])

print(max(int(0), ri - le + 1))

def extgcd(a, b):
    x, y = 0, 0
    d = a;
    if b != 0:
        d, y, x = extgcd(b, a%b)
        y -= (a//b) * x
    else:
        x, y = 1, 0
    return (d, x, y)

def main():
    a1, b1, a2, b2, L, R = map(int, input().split())
    g, k, l = extgcd(a1, a2);
    b = b2-b1;
    if (b%g != 0):
        print (0)
        return
    k *= b//g
    l *= -b//g
    low = -2**100
    high = 2**100
    while high-low > 1:
        med = (low+high)//2
        tk = k+med*a2//g
        tl = l+med*a1//g
        if (tk >= 0 and tl >= 0):
            high = med
        else:
            low = med
    k = k+high*a2//g
    x = a1*k+b1
    if x > R:
        print (0)
        return
    low = -1
    high = 2**100
    lcm = a1*a2//g
    while high - low > 1:
        med = (low+high)//2
        tx = x+med*lcm
        if tx >= L:
            high = med
        else:
            low = med
    x = x+med*lcm
    low = 0
    high = 2**100
    while high-low > 1:
        med = (low+high)//2
        tx = x+med*lcm
        if (tx <= R):
            low = med
        else:
            high = med
    if low == 0 and x > R:
        print (0)
        return
    print (low+1)
    return

if __name__=="__main__":
    main()

def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
if c%g != 0 :
 print (0)
 exit (0)
i = -(a*(x*c)+aa)
step = a*b//g
f = max (0,(l-i)//step)
s = (r-i)//step
print (abs (s-f)+1)

def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
if c%g != 0 :
 print (0)
 exit (0)
i = a*(x*c)+aa
step = a*b//g

# shift i to la,lb
if i >= max(aa,bb) :
 i -= (i-max(aa,bb))//step * step
else :
 i += ((max(aa,bb)-i)//step + 1) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
#print("c",c,g)
if c%g != 0 :
 print (0)
 exit (0)
# ax-by = cc = bb-aa
# ax-by = g(cc) = bb-aa
#print(x,y)
i = a*(x*c)//g+aa
ii = b*(y*c)//g+bb
step = a*b//g
#print(a,x,c , " | ",b,y,c)
#print(i,ii,step)
if (ii-i) % step != 0 :
 print(0)
 exit(0)
#print(a,x,c,aa)

#print(i,ii,step)
# shift i to la,lb
if i >= max(aa,bb) :
 i -= (i-max(aa,bb))//step * step
elif i <= max(aa,bb) :
 i += ((max(aa,bb)-i)//step + 1) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

import math
def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
#print("c",c,g)
if c%g != 0 :
 print (0)
 exit (0)
# ax-by = cc = bb-aa
# ax-by = g(cc) = bb-aa
#print(x,y)
i = a*(x*c)//g+aa
ii = (-b*(y*c)//g)+bb
#print(a*x//g*c,b*y//g*c,aa,bb)
step = a*b//g
#print(a,x,c , " | ",b,y,c)
#print(i,ii,step)
if (ii-i) % step != 0 :
 print(0)
 exit(0)
#print(a,x,c,aa)

#print(i,ii,step)
# shift i to la,lb
#print(i,aa,bb)
if i > max(aa,bb) :
 i -= ((i-max(aa,bb))//step + (1 if (i-max(aa,bb))%step!=0 else 0)) * step
elif i < max(aa,bb) :
 i += ((max(aa,bb)-i)//step + (1 if (max(aa,bb)-i)%step!=0 else 0)) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
if c%g != 0 :
 print (0)
 exit (0)
i = a*(x*c)+aa
step = a*b//g

# shift i to la,lb
if i >= max(aa,bb) :
 i -= (i-max(aa,bb))//step * step
elif i <= max(aa,bb) :
 i += ((max(aa,bb)-i)//step + 1) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
#print("c",c,g)
if c%g != 0 :
 print (0)
 exit (0)
# ax-by = cc = bb-aa
# ax-by = g(cc) = bb-aa
#print(x,y)
i = a*(x*c)//g+aa
ii = (-b*(y*c)//g)+bb
#print(a*x//g*c,b*y//g*c,aa,bb)
step = a*b//g
#print(a,x,c , " | ",b,y,c)
#print(i,ii,step)
if (ii-i) % step != 0 :
 print(0)
 exit(0)
#print(a,x,c,aa)

#print(i,ii,step)
# shift i to la,lb
if i >= max(aa,bb) :
 i -= (i-max(aa,bb))//step * step
elif i <= max(aa,bb) :
 i += ((max(aa,bb)-i)//step + 1) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

import math
def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
#print("c",c,g)
if c%g != 0 :
 print (0)
 exit (0)
# ax-by = cc = bb-aa
# ax-by = g(cc) = bb-aa
#print(x,y)
i = a*(x*c)//g+aa
ii = (-b*(y*c)//g)+bb
#print(a*x//g*c,b*y//g*c,aa,bb)
step = a*b//g
#print(a,x,c , " | ",b,y,c)
#print(i,ii,step)
if (ii-i) % step != 0 :
 print(0)
 exit(0)
#print(a,x,c,aa)

#print(i,ii,step)
# shift i to la,lb
#print(i,aa,bb)
if i > max(aa,bb) :
 i -= int(math.ceil(i-max(aa,bb))/step) * step
elif i < max(aa,bb) :
 i += int(math.ceil(max(aa,bb)-i)/step) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
if c%g != 0 :
 print (0)
 exit (0)
i = a*(x*c)+aa
step = a*b//g

# shift i to la,lb
if i >= max(aa,bb) :
 i -= (i-max(aa,bb))//step * step
else :
 i += ((max(aa,bb)-i)//step + 1) * step

f = max (0,(l-i)//step)
s = (r-i)//step
#print(i,step,f,s)
print (max(0,s-f+1))

import math
def xgcd (b,n) :
 x0,x1,y0,y1 = 1,0,0,1
 while n != 0 :
  q,b,n = b//n , n , b % n
  x0,x1 = x1, x0-q*x1
  y0,y1 = y1,y0-q*y1
 return b,x0,y0
a,aa,b,bb,l,r = [int (x) for x in input ().split ()]
g,x,y=xgcd (a,b)
c = bb-aa
#print("c",c,g)
if c%g != 0 :
 print (0)
 exit (0)
# ax-by = cc = bb-aa
# ax-by = g(cc) = bb-aa
#print(x,y)
i = a*(x*c)//g+aa
ii = (-b*(y*c)//g)+bb
#print(a*x//g*c,b*y//g*c,aa,bb)
step = a*b//g
#print(a,x,c , " | ",b,y,c)
#print(i,ii,step)
if (ii-i) % step != 0 :
 print(0)
 exit(0)
#print(a,x,c,aa)

#print(i,ii,step)
# shift i to la,lb
#print(i,aa,bb)
if i > max(aa,bb) :
 i -= ((i-max(aa,bb))//step + (1 if (i-max(aa,bb))%step!=0 else 0)) * step
elif i < max(aa,bb) :
 i += ((max(aa,bb)-i)//step + (1 if (max(aa,bb)-i)%step!=0 else 0)) * step

f = (l-i)//step
if (l-i) % step != 0 : f+=1
f = max(f,0)
s = (r-i)//step
print(i,step,f,s)
print (max(0,s-f+1))

from collections import defaultdict
import sys, os, math

def gcd(a1, a2):
    if a2 == 0:
        return a1
    else:
        return gcd(a2, a1 % a2)

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)
if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a1, b1, a2, b2, L, R = map(int, input().split())
    a2 *= -1
    LCM = a1 * a2 // gcd(a1, a2)
    if abs(b1 - b2) % gcd(a1, a2) != 0:
        print(0)
        sys.exit(0)
    L = max([b1, b2, L])
    g, x, y = egcd(a1, a2)
    X = a1 * x * (b2 - b1) // g + b1
    X += LCM * math.ceil((L - X) / LCM)
    print(max(0, (R - X) // LCM + 1))

from collections import defaultdict
import sys

def gcd(a1, a2):
    if a2 == 0:
        return a1
    else:
        return gcd(a2, a1 % a2)
if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a1, b1, a2, b2, L, R = map(int, input().split())
    LCM = a1 * a2 // gcd(a1, a2)
    if abs(b1 - b2) % gcd(a1, a2) != 0:
        print(0)
        sys.exit(0)
    for i in range(max([b1, b2, L]), R + 1):
        if (i - b1) % a1 == 0 and (i - b2) % a2 == 0:
            print((R - i) // LCM + 1)
            break

from collections import defaultdict
import sys

def gcd(a1, a2):
    if a2 == 0:
        return a1
    else:
        return gcd(a2, a1 % a2)
if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a1, b1, a2, b2, L, R = map(int, input().split())
    LCM = a1 * a2 // gcd(a1, a2)
    for i in range(L, R + 1):
        if (i - b1) % a1 == 0 and (i - b2) % a2 == 0:
            print((R - i) // LCM + 1)
            sys.exit(0)
    print(0)

from collections import defaultdict
import sys, os, math

def gcd(a1, a2):
    if a2 == 0:
        return a1
    else:
        return gcd(a2, a1 % a2)

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)
if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a1, b1, a2, b2, L, R = map(int, input().split())
    LCM = a1 * a2 // gcd(a1, a2)
    if abs(b1 - b2) % gcd(a1, a2) != 0:
        print(0)
        sys.exit(0)
    L = max([b1, b2, L])
    g = egcd(a1, a2)[0]
    g += LCM * math.ceil((L - egcd(a1, a2)[0]) / LCM)
    print(max(0, (R - g) // LCM + 1))

from math import gcd
def exd_gcd(a, b):
  # always return as POSITIVE presentation
  if a % b == 0:
    return 0, (1 if b > 0 else -1)
  x, y = exd_gcd(b, a % b)
  return y, x - a // b * y
def interval_intersect(a, b, c, d):
  if b <= a or d <= c:
    return 0
  if c < a:
    a, b, c, d = c, d, a, b
  if c < b:
    return min(b, d) - c
  else:
    return 0
def ceil(a, b):
  return (a + b - 1) // b

a1, b1, a2, b2, L, R = map(int, input().split())
g = gcd(a1, a2)
if (b1 - b2) % g != 0:
  print(0)
  exit(0)
k, l = exd_gcd(a1, a2)
l = -l
k *= (b2 - b1) // g
l *= (b2 - b1) // g
d1 = a2 // g
d2 = a1 // g
assert(k * a1 + b1 == l * a2 + b2)
arb = 3238
assert((k + arb * d1) * a1 + b1 == (l + arb * d2) * a2 + b2)
L1, R1 = ceil(max(0, ceil(L - b1, a1)) - k, d1), ((R - b1) // a1 - k) // d1
L2, R2 = ceil(max(0, ceil(L - b2, a2)) - k, d2), ((R - b2) // a2 - k) // d2
print(interval_intersect(L1, R1 + 1, L2, R2 + 1))

from math import gcd
def exd_gcd(a, b):
  # always return as POSITIVE presentation
  if a % b == 0:
    return 0, (1 if b > 0 else -1)
  x, y = exd_gcd(b, a % b)
  return y, x - a // b * y
def interval_intersect(a, b, c, d):
  if b <= a or d <= c:
    return 0
  if c < a:
    a, b, c, d = c, d, a, b
  if c < b:
    return min(b, d) - c
  else:
    return 0
def ceil(a, b):
  return (a + b - 1) // b

a1, b1, a2, b2, L, R = map(int, input().split())
g = gcd(a1, a2)
if (b1 - b2) % g != 0:
  print(0)
  exit(0)
k, l = exd_gcd(a1, a2)
l = -l
k *= (b2 - b1) // g
l *= (b2 - b1) // g
d1 = a2 // g
d2 = a1 // g
assert(k * a1 + b1 == l * a2 + b2)
arb = 3238
assert((k + arb * d1) * a1 + b1 == (l + arb * d2) * a2 + b2)
L1, R1 = ceil(max(0, ceil(L - b1, a1)) - k, d1), ((R - b1) // a1 - k) // d1
L2, R2 = ceil(max(0, ceil(L - b2, a2)) - l, d2), ((R - b2) // a2 - l) // d2
print(L1 * d1 + k, R1 * d1 + k)
print(L2 * d2 + k, R2 * d2 + k)
print(interval_intersect(L1, R1 + 1, L2, R2 + 1))

def exgcd(i, j):
    if j == 0:
        return 1, 0, i
    u, v, d = exgcd(j, i % j)
    return v, u - v * i // j, d

ma, ra, mb, rb, L, R = map(int, input().split(' '))
L = max(L, ra, rb)

if L > R:
    print(0)
    exit(0)

ra %= ma
rb %= mb

if ra > rb:
    ma, ra, mb, rb = mb, rb, ma, ra

_, _, md = exgcd(ma, mb)

if md != 1:
    if (rb - ra) % md != 0:
        print(0)
        exit(0)
    m = ma * mb // md
    rev, _, _ = exgcd(ma // md, mb // md)
    rev = (rev % (mb // md) + mb // md) % (mb // md)
    r = ma * (rb - ra) // md * rev + ra
    r = (r % m + m) % m
else:
    m = ma * mb
    bv, av, _ = exgcd(ma, mb)
    r = ra * mb * av + rb * ma * bv
    r = (r % m + m) % m

def calc(i):
    return (i - r) // m

print(calc(R) - calc(L - 1))

def exgcd(i, j):
    if j == 0:
        return 1, 0, i
    u, v, d = exgcd(j, i % j)
    return v, u - v * i // j, d

ma, ra, mb, rb, L, R = map(int, input().split(' '))

ra %= ma
rb %= mb

if ra > rb:
    ma, ra, mb, rb = mb, rb, ma, ra

_, _, md = exgcd(ma, mb)

if md != 1:
    if (rb - ra) % md != 0:
        print(0)
        exit(0)
    m = ma * mb // md
    rev, _, _ = exgcd(ma // md, mb // md)
    rev = (rev % (mb // md) + mb // md) % (mb // md)
    r = ma * (rb - ra) // md * rev + ra
    r = (r % m + m) % m
else:
    m = ma * mb
    bv, av, _ = exgcd(ma, mb)
    r = ra * mb * av + rb * ma * bv
    r = (r % m + m) % m

def calc(i):
    return (i - r) // m

print(calc(R) - calc(L - 1))

def euc(a, b): #requires a>=b
    if a%b==0:
        return [b, 0, 1]
    else:
        return [euc(b, a%b)[0], euc(b, a%b)[2], euc(b, a%b)[1]-euc(b, a%b)[2]*(a/b)]

stuff=raw_input().split()
a1=int(stuff[0])
b1=int(stuff[1])
a2=int(stuff[2])
b2=int(stuff[3])
L=int(stuff[4])
R=int(stuff[5])

if a1<a2: #make a1>=a2
    a1, a2=a2, a1
    b1, b2=b2, b1

L=max(b1, b2, L) #accounts for >=0 restriction

if a1*a2==0: #handling dumb zero cases
    if a1==0 and a2==0:
        if b1==b2 and L<=b1 and b1<=R:
            print 1
        else:
            print 0
    elif a1==0:
        if (b1-b2) % a2==0 and L<=b1 and b1<=R:
            print 1
        else:
            print 0
    elif a2==0:
        if (b2-b1) % a1==0 and L<=b2 and b2<=R:
            print 1
        else:
            print 0
else:
    l=euc(a1, a2)
    gcd=l[0]
    a1coeff=l[1]
    a2coeff=l[2]
    if (b1-b2)%gcd==0:
        #now we solve for (x-b1)/gcd and apply CRT, using Euc to speed up the process
        q=a1*(b2-b1)/gcd * a1coeff + b1
        p=a1*a2/gcd
        print (R-q)/p - (L-q-1)/p
    else:
        print 0

import sys
from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (a,1,0)
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return g,x,y

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = a1
B = a2
C = b2 - b1

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print 0
    sys.exit(0)

X = X*C/G
Y = Y*C/G

K = max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] )

#print int(K)

#print "LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 )
#print "UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 )
#print "S", a1 * (X + B*K/G) + b1, "T", a2 * (-Y + A*K/G) + b2

K = max( [ K, math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) ) ] )

ANS = math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) ) - K + 1

print max( [ 0, int(ANS) ] )

from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (a,1,0)
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return g,x,y

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = a1
B = a2
C = b2 - b1

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print 0
    sys.exit(0)

X = X*C/G
Y = Y*C/G

K = max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] )

print int(K)

print "LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 )
print "UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 )
print "S", a1 * (X + B*K/G) + b1, "T", a2 * (-Y + A*K/G) + b2

K = max( [ K, math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) ) ] )

ANS = math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) ) - K + 1

print max( [ 0, int(ANS) ] )

import sys
from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (a,1,0)
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return g,x,y

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = a1
B = a2
C = b2 - b1

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print 0
    sys.exit(0)

X = X*C/G
Y = Y*C/G

K = int(max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] ))

# print "A",A,"B",B
# print "G",G
# print "X",X,"Y",Y
# print "K",int(K)

# print "LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 )
# print "UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 )
# print "S", a1 * (X + B*int(K)/G) + b1, "T", a2 * (-Y + A*int(K)/G) + b2

K = int(max( [ K, math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) ) ] ))

U = int(math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) ))

while a1 * (X + B*int(K)/G) + b1 < L:
    K = K + 1

if K > U or a1 * (X + B*int(K)/G) + b1 > R:
    ANS = 0;
else:
    ANS = U - K + 1

print max( [ 0, int(ANS) ] )

import sys
from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (a,1,0)
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return g,x,y

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = a1
B = a2
C = b2 - b1

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print 0
    sys.exit(0)

X = X*C/G
Y = Y*C/G

K = int(max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] ))

# print "A",A,"B",B
# print "G",G
# print "X",X,"Y",Y
# print "K",int(K)

# print "LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 )
# print "UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 )
# print "S", a1 * (X + B*int(K)/G) + b1, "T", a2 * (-Y + A*int(K)/G) + b2

K = int(max( [ K, math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) ) ] ))

U = int(math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) ))

while a1 * (X + B*int(K)/G) + b1 < L:
    K = K + 1

if K > U:
    ANS = 0;
else:
    ANS = U - K + 1

print max( [ 0, int(ANS) ] )

from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (a,1,0)
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return g,x,y

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = a1
B = a2
C = b2 - b1

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print 0
    sys.exit(0)

X = X*C/G
Y = Y*C/G

K = max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] )

# print int(K)

# print "LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 )
# print "UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 )
# print "S", a1 * (X + B*K/G) + b1, "T", a2 * (-Y + A*K/G) + b2

K = max( [ K, math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) ) ] )

ANS = math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) ) - K + 1

print int(ANS)

import sys
from fractions import gcd
from math import sqrt,log
import time
from random import randint
import random
from sets import Set
# ---------- Number Theory -------------#
def primes_upto(maxn):
    maxn+=1
    A = [False]*(maxn/2+5)
    p = 3
    while p*p<maxn:
        if not A[p>>1]:
            for j in range(p*p,maxn,2*p):
                A[(j>>1)]=True
        p+=2
    ret = [2]
    for p in range(3,maxn,2):
        if not A[(p>>1)]:
            ret.append(p)
    return ret
st = time.time()
prime_list = primes_upto(1000000)
def factor_sieve(maxn):
    maxn+=1
    factor = [0]*maxn
    lim  = int(sqrt(maxn))
    for i in range(2,lim+2):
        if factor[i] == 0:
            for j in range(i*i,maxn,i):
                factor[j] = i
    return factor
factor_list = factor_sieve(100000)
def totient_sieve(maxn): #returns an array of totient function
    factor=[]
    if maxn<100000:
        factor = factor_list
    else:
        factor = factor_sieve(maxn)
    maxn+=1
    tot = [1]*maxn
    tot[0] = 0
    for i in range(2,maxn):
        if factor[i] == 0:
            tot[i] = i-1
            continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            tot[i] = tot[y]*x
        else:
            tot[i] = tot[y]*(x-1)
    return tot
def mobius_sieve(maxn):
    factor=[]
    if maxn<100000:
        factor = factor_list
    else:
        factor = factor_sieve(maxn)
    maxn+=1
    mu = [1]*maxn
    for i in range(2,maxn):
        if factor[i] == 0:
            mu[i]=-1
            continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            mu[i] = 0
        else:
            mu[i]=mu[x]*mu[y]
    return mu
def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n-1:
            return False
    return True # n  is definitely composite

def is_prime(n, _precision_for_huge_n=10):
    if n in _known_primes or n in (0, 1):
        return True
    for p in _known_primes:
        if n%p==0:
            return False
    d, s = n - 1, 0
    while not d % 2:
        d, s = d >> 1, s + 1
    # Returns exact according to http://primes.utm.edu/prove/prove2_3.html
    if n < 1373653:
        return not any(_try_composite(a, d, n, s) for a in (2, 3))
    if n < 25326001:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5))
    if n < 118670087467:
        if n == 3215031751:
            return False
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7))
    if n < 2152302898747:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11))
    if n < 3474749660383:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13))
    if n < 341550071728321:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
    return not any(_try_composite(a, d, n, s)
                   for a in _known_primes[:_precision_for_huge_n])

_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
def brent(N):#Fails for perfect squares,primes
        if N%2==0:
                return 2
        if N<100000:
            return factor_list[N]
        y,c,m = random.randint(1, N-1),random.randint(1, N-1),random.randint(1, N-1)
        g,r,q = 1,1,1
        while g==1:
                x = y
                for i in range(r):
                        y = ((y*y)%N+c)%N
                k = 0
                while (k<r and g==1):
                        ys = y
                        for i in range(min(m,r-k)):
                                y = ((y*y)%N+c)%N
                                q = q*(abs(x-y))%N
                        g = gcd(q,N)
                        k = k + m
                r = r*2
        if g==N:
                while True:
                        ys = ((ys*ys)%N+c)%N
                        g = gcd(abs(x-ys),N)
                        if g>1:
                                break

        return g
def floor_sqrt(n):
    x = max(0,int(sqrt(n))-1)
    while x*x<=n:
        x+=1
    return x-1
def prime_factors(n):# Returns all prime factors of n
    ret = Set()
    if n==1:
        return ret
    if is_prime(n):
        ret.add(n)
        return ret
    x = floor_sqrt(n)
    if x*x == n:
        return prime_factors(x)
    x = brent(n)
    n/=x
    while n%x == 0:
        n/=x
    r1 = prime_factors(x)
    r2 = prime_factors(n)
    for i in r1:
        ret.add(i)
    for i in r2:
        ret.add(i)
    return ret
def factorization(n):
    X = prime_factors(n)
    arr = []
    for i in X:
        arr.append(i)
    ret = {}
    for i in range(0,len(arr)):
        val = 0
        p = arr[i]
        while n%p == 0:
            val+=1
            n/=p
        ret[p] = val
    assert(n==1)
    return ret
def divisors(n):
    X = factorization(n)
    A=[1]
    for p in X:
        a = X[p]
        x=p**a
        z=len(A)
        B = A
        for i in range(0,z):
            val=A[i]
            mul = p
            for j in range(1,a+1):
                B.append(val*mul)
                mul*=p
        A = B
    return A
def ndiv(n):
    x = factorization(n)
    ret=1
    for i in x:
        ret*=x[i]+1
    return ret
def sorted_divisors(n):
    return sorted(divisors(n))
myp = {}
def primepi(n):#Finds pi(10**10) in 12 secs, pi(10**11) in 1 minute O(sqrt(n)) memory
    if n<=1:
        return 0
    if myp.has_key(n):
        return myp[n]
    myp.clear()
    lim=floor_sqrt(n)
    sm=[]
    la =[]
    for i in range(0,lim+1):
        sm.append(i-1)
        if i==0:
            la.append(0)
            continue
        la.append(n/i-1)
    for p in range(2,lim+1):
        if sm[p-1] == sm[p]:
            continue
        cnt_p = sm[p-1]
        q = p*p
        en = min(lim,n/q)
        for i in range(1,en+1):
            d = i*p
            if d<=lim:
                la[i]-=la[d]-cnt_p
            else:
                la[i]-=sm[n/d]-cnt_p
        for i in range(lim,q-1,-1):
            sm[i]-=sm[i/p]-cnt_p
    for i in range(1,lim+1):
        myp[i] = sm[i]
        myp[n/i] = la[i]
    return la[1]
cache={}
def phi(n): #totient(n)
    if n in cache:
        return cache[n]
    ret = n
    x = prime_factors(n)
    for p in x:
        ret*=p-1
        ret/=p
    cache[n] = ret
    return ret

def inv(x,a): #(x,a) = 1
    r = phi(a)-1
    ret= pow(x,r,a)
    return ret

def crt(A,B):# all elements of A are mutually coprime
    N = 1
    for i in range(0,len(A)):
        N*=A[i]
    ret = 0
    for i in range(0,len(A)):
        val = A[i]
        md = B[i]
        prod_rem = N/val
        ret+=md*(prod_rem*inv(prod_rem,val))
    ans= ret%N
    return ans
_store = {}
a1,b1,a2,b2,l,r = map(int,raw_input().split())
l = max(l,max(b1,b2))
if l > r:
    print 0
    sys.exit()
g = gcd(a1,a2)
if (b1%g + g)%g != (b2%g + g)%g:
    print 0
    sys.exit()
X = (a1*a2)/g
x = (b1%(a1/g) +(a1/g))%(a1/g) # modulo a1/g
y = (b2%a2 + a2)%a2 # modulo a2

P = [x,y]
Q = [a1/g,a2]
rem = crt(Q,P)
# number of numbers between l,r, which are rem modulo X
size = r-l
l = (l%X + X)%X + 10*X - rem
r = l+size
print(r/X- (l-1)/X)

a1,b1,a2,b2,l,r=map(int,raw_input().split())
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

lst1=[]
lst2=[]
for i in range(ks1,ke1+2):
    if(a1*i+b1>=l and a1*i+b1<=r):
        lst1.append(a1*i+b1)
for i in range(ks2,ke2+2):
    if(a2*i+b2>=l and a2*i+b2<=r):
        lst2.append(a2*i+b2)

set1=set(lst1)
set2=set(lst2)

l=len(set1.intersection(set2))
print l

a1,b1,a2,b2,l,r=map(int,raw_input().split())
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

lst1=[]
lst2=[]
for i in range(ks1-1,ke1+2):
    if(a1*i+b1>=l or a1*i+b1<=r):
        lst1.append(a1*i+b1)
for i in range(ks2-1,ke2+2):
    if(a2*i+b2>=l or a2*i+b2<=r):
        lst2.append(a2*i+b2)

set1=set(lst1)
set2=set(lst2)
l=len(set1.intersection(set2))
print l

a1,b1,a2,b2,l,r=map(int,raw_input().split())
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

lst1=[]
lst2=[]
for i in range(ks1,ke1+1):
    lst1.append(a1*i+b1)
for i in range(ks2,ke2+1):
    lst2.append(a2*i+b2)

set1=set(lst1)
set2=set(lst2)
l=len(set1.intersection(set2))
print l

from fractions import gcd
a1,b1,a2,b2,l,r=map(int,raw_input().split())
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2
b1=(b1-l)%a1+l
b2=(b2-l)%a2+l
g=gcd(a1,a2)
var=a1/g*a2
lst1=[]
lst2=[]
ks1=max(b1,b2)

m=min(1+r,var+ks1)
while b1!=b2 and m>b1:
    if b1<b2:
        b1=(b1-b2)%a1+b2
    else:
        b2=(b2-b1)%a2+b1
if(m>b1):
    print (1+(r-b1)/var)
else:
    print "0"

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

def gcd(x,y):
    while y:
        x,y=y,x%y
    return x

def modpow(x,y,m):
    # (x**y) % m
    if y==0: return 1%m
    elif y==1: return x%m
    elif y&1: return (modpow((x*x)%m,y//2,m)*x)%m
    else: return modpow((x*x)%m,y//2,m)

def inv(x,m):
    # return the inverse of x, modulo m
    # use euler's theorem
    tot=m
    mt=m
    for i in range(2,mt):
        if i*i>mt: break
        if mt%i==0:
            tot//=i
            tot*=i-1
            while mt%i==0: mt//=i
    if mt>1:
        tot//=mt
        tot*=mt-1
    # totient(m) = tot
    return modpow(x%m,tot-1,m)

def crt(x1,m1,x2,m2):
    # chinese remainder theorem solver
    # clean up
    m1=abs(m1)
    m2=abs(m2)
    x1%=m1
    x2%=m2
    if m1>m2:
        m1,m2=m2,m1
        x1,x2=x2,x1
    # get out a factor
    t=gcd(m1,m2)
    if x1%t or x2%t:
        print("Something went wrong with the no intersection step")
    x1//=t
    m1//=t
    x2//=t
    m2//=t
    # get important numbers
    # r1 is 1 mod m1 and 0 mod m2
    # r2 is 0 mod m1 and 1 mod m2
    r1=(m2*inv(m2,m1))%(m1*m2)
    r2=(m1*inv(m1,m2))%(m1*m2)
    # pretty much done
    return t*((x1*r1+x2*r2)%(m1*m2))

# k',l'>=0 is the most annoying thing ever
a1,b1,a2,b2,l,r=map(int,input().split())

# bound l,r so nothing breaks
if a1>=0: l=max(l,b1)
if a1<=0: r=min(r,b1)
if a2>=0: l=max(l,b2)
if a2<=0: r=min(r,b2)

if l>r: print(0)
elif l==r:
    # special case
    # b1,b2=0 leads here
    ans=1
    if b1!=l and (l-b1)%a1!=0: ans=0
    if b2!=l and (l-b2)%a2!=0: ans=0
    print(ans)
elif gcd(b1,b2)%gcd(a1,a2)!=0:
    # they don't intersect
    print(0)
else:
    # general case is the best case
    a3=abs((a1*a2)//gcd(a1,a2))
    b3=crt(b1,a1,b2,a2)
    # solve stuff easily now
    # python rounds down always
    l=(l-b3+a3-1)//a3
    r=(r-b3)//a3
    print(max(0,r-l+1))

MAXI = 2 * (10 ** 10)

def sign(x):
    return 1 if x >= 0 else -1

def cstyle_int(x):
    if x == 0:
        return 0
    s = 1 if x >= 0 else -1
    x = abs(x)
    return s * int(x)

def exgcd(a, b):
    if b == 0:
       return (a, 1, 0)
    (r, x, y) = exgcd(b, a % b)
    t = y
    y = x - (a / b) * y
    x = t
    return (r, x, y)

def solve(a1, b1, a2, b2, L, R):
    a, b, c = a2, b2 - b1, a1
    llx = sign(L - b1 + a1 - 1) * abs(L - b1 + a1 - 1) / a1
    rrx = sign(R - b1) * abs(R - b1) / a1

    lly = sign(L - b2 + a2 - 1) * abs(L - b2 + a2 - 1) / a2
    rry = sign(R - b2) * abs(R - b2) / a2

    ll = c * llx - b
    rr = c * rrx - b

    ll = sign(ll + a - 1) * abs(ll + a - 1) / a
    rr = sign(rr) * abs(rr) / a

    ll = max(lly, ll)
    rr = min(rry, rr)
    #print rr, ll

    (r, w, v) = exgcd(a1, a2)
    w = -w

    if (b1 - b2) % r != 0:
        return 0
    else:
        base1 = (b1 - b2) / r * w * a1 + b1
        base2 = (b1 - b2) / r * v * a2 + b2
        assert base1 == base2
        base = base1

        lcm = a1 * a2 / r
        #print base, lcm
        #print '>>', ll, rr, (rr * a2 + b2), (ll * a2 + b2)
        base -= (base / lcm + 1) * lcm
        while base > 0:
            base -= lcm
        #print base
        #print (rr * a2 + b2 - base) / lcm , (ll * a2 + b2 - 1 - base) / lcm
        return (rr * a2 + b2 - base) / lcm - (ll * a2 + b2 - 1 - base) / lcm

assert solve(2, 4, 3, 0, 6, 17) == 2
assert solve(2, 0, 3, 3, 5, 21) == 3

if __name__ == '__main__':
    (a1, b1, a2, b2, L, R) = map(int, raw_input().split())
    print solve(a1, b1, a2, b2, L, R)

MAXI = 2 * (10 ** 10)

def sign(x):
    return 1 if x >= 0 else -1

def cstyle_int(x):
    if x == 0:
        return 0
    s = 1 if x >= 0 else -1
    x = abs(x)
    return s * int(x)

def exgcd(a, b):
    if b == 0:
       return (a, 1, 0)
    (r, x, y) = exgcd(b, a % b)
    t = y
    y = x - (a / b) * y
    x = t
    return (r, x, y)

def solve(a1, b1, a2, b2, L, R):
    a, b, c = a2, b2 - b1, a1
    llx = sign(L - b1 + a1 - 1) * abs(L - b1 + a1 - 1) / a1
    rrx = sign(R - b1) * abs(R - b1) / a1

    llx = max(llx, 0)
    rrx = max(rrx, 0)

    lly = sign(L - b2 + a2 - 1) * abs(L - b2 + a2 - 1) / a2
    rry = sign(R - b2) * abs(R - b2) / a2

    lly = max(lly, 0)
    rry = max(rry, 0)

    ll = c * llx - b
    rr = c * rrx - b

    ll = sign(ll + a - 1) * abs(ll + a - 1) / a
    rr = sign(rr) * abs(rr) / a

    ll = max(lly, ll)
    rr = min(rry, rr)
    #print rr, ll

    (r, w, v) = exgcd(a1, a2)
    w = -w

    if (b1 - b2) % r != 0:
        return 0
    else:
        base1 = (b1 - b2) / r * w * a1 + b1
        base2 = (b1 - b2) / r * v * a2 + b2
        assert base1 == base2
        base = base1

        lcm = a1 * a2 / r
        #print base, lcm
        #print '>>', ll, rr, (rr * a2 + b2), (ll * a2 + b2)
        base -= (base / lcm + 1) * lcm
        while base > 0:
            base -= lcm
        #print base
        #print (rr * a2 + b2 - base) / lcm , (ll * a2 + b2 - 1 - base) / lcm
        return (rr * a2 + b2 - base) / lcm - (ll * a2 + b2 - 1 - base) / lcm

def brute_force(a1, b1, a2, b2, L, R):
    i = 0
    sa, sb = set(), set()
    while a1 * i + b1 <= R:
        if a1 * i + b1 >= L:
            sa.add(a1 * i + b1)
        i += 1

    i = 0
    while a2 * i + b2 <= R:
        if a2 * i + b2 >= L:
            sb.add(a2 * i + b2)
        i += 1
    return len(sa & sb)

def test(*args):
    assert solve(*args) == brute_force(*args)

assert solve(2, 4, 3, 0, 6, 17) == 2
assert solve(2, 0, 3, 3, 5, 21) == 3
assert solve(2, 0, 3, 3, 5, 21) == brute_force(2, 0, 3, 3, 5, 21)
test(4, 2, 4, 4, 8, 200)
test(9, 2, 4, 4, 8, 200)
test(9, -2, 4, 4, 8, 200)

if __name__ == '__main__':
    (a1, b1, a2, b2, L, R) = map(int, raw_input().split())
    print solve(a1, b1, a2, b2, L, R)

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    X -= (X//dd) * dd
    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd

    if X > k:
        return 0

    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L-b1+a1-1)//a1
d1 *= a1
d1 -= b1
d2 = (L-b2+a2-1)//a2
d2 *= a2
d2 -= b2

if R < max(d1, d2):
    print(0)
else:
    if d1 > d2:
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    X -= (X//dd) * dd
    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd

    if X > k:
        return 0

    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L-b1)//a1
if d1 < 0:
    d1 = 0
d1 *= a1
d1 -= b1
d2 = (L-b2)//a2
if d2 < 0:
    d2 = 0
d2 *= a2
d2 -= b2

while d1 < L:
    d1 += a1
while d2 < L:
    d2 += a2

#print(d1, d2, L, R)
if R < max(d1, d2):
    print(0)
else:
    if d1 > d2 or (d1 == d2 and a1 < a2):
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    if X >= 0:
        X -= (X//dd) * dd
    else:
        g = X//dd
        if g * dd > X:
            g += 1
        X -= g * dd

    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd

    if X > k:
        return 0
    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L-b1)//a1
if d1 < 0:
    d1 = 0
d1 *= a1
d1 += b1
d2 = (L-b2)//a2
if d2 < 0:
    d2 = 0
d2 *= a2
d2 += b2

while d1 < L:
    d1 += a1
while d2 < L:
    d2 += a2

#print(d1, d2, L, R)

if R < max(d1, d2):
    print(0)
else:
    if a1 < a2:
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    if X >= 0:
        X -= (X//dd) * dd
    else:
        g = X//dd
        if g * dd > X:
            g += 1
        X -= g * dd

    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd

    if X > k:
        return 0
    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L-b1)//a1
if d1 < 0:
    d1 = 0
d1 *= a1
d1 += b1
d2 = (L-b2)//a2
if d2 < 0:
    d2 = 0
d2 *= a2
d2 += b2

while d1 < L:
    d1 += a1
while d2 < L:
    d2 += a2

#print(d1, d2, L, R)

if R < max(d1, d2):
    print(0)
else:
    if d1 > d2 or (d1 == d2 and a1 < a2):
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    X -= (X//dd) * dd
    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd
    if X > k:
        return 0
    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L+b1+a1-1)//a1
d1 *= a1
d1 += b1
d2 = (L+b2+a2-1)//a2
d2 *= a2
d2 += b2

if R < max(d1, d2):
    print(0)
else:
    if d1 > d2:
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

def gcd(a, b):
    if a==0:
        return (b, 0, 1)
    g, x1, y1 = gcd(b%a, a)
    x = y1 - (b // a) * x1
    y = x1
    return (g, x, y)

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    X -= (X//dd) * dd
    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd

    if X > k:
        return 0

    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L-b1)//a1
if d1 < 0:
    d1 = 0
d1 *= a1
d1 -= b1
d2 = (L-b2)//a2
if d2 < 0:
    d2 = 0
d2 *= a2
d2 -= b2

if R < max(d1, d2):
    print(0)
else:
    if d1 > d2:
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))

from fractions import gcd
a1,b1,a2,b2,l,r=map(int,input().split())

if b1<l:
    b1=(b1-l)%a1+l
if b2<l:
    b2=(b2-l)%a2+l
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

g=gcd(a1,a2)
var=a1/g*a2
lst1=[]
lst2=[]
ks1=max(b1,b2)

m=min(1+r,var+ks1)
while b1!=b2 and m>b1:
    if b1<b2:
        b1=(b1-b2)%a1+b2
    else:
        b2=(b2-b1)%a2+b1
if(m>b1):
    print (1+(r-b1)//var)
else:
    print ("0")

from fractions import gcd
a1,b1,a2,b2,l,r=map(int,input().split())

if b1<l:
    b1=(b1-l)%a1+l
if b2<l:
    b2=(b2-l)%a2+l
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

g=gcd(a1,a2)
var=a1/g*a2
lst1=[]
lst2=[]
ks1=max(b1,b2)

m=min(1+r,var+ks1)
while b1!=b2 and m>b1:
    if b1<b2:
        b1=(b1-b2)%a1+b2
    else:
        b2=(b2-b1)%a2+b1
if(m>b1):
    print (1+(r-b1)/var)
else:
    print ("0")

import sys

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def extgcd(a, b):
    if b == 0: return 1, 0
    x, y = extgcd(b, a % b)
    return y, x - a // b * y

def modinv(a, mod):
    if a == 0: return -1
    if gcd(a, mod) != 1: return -1
    return extgcd(a, mod)[0] % mod

def solve(a1, b1, a2, b2):
    g = gcd(a1, a2)
    a1 //= g
    a2 *= g
    if a1 == a2:
        if b1 % a1 == b2 % a2: return b1
        return -1
    u = b1 % a1
    inv = modinv(a1, a2)
    if inv == -1: return -1
    v = (b2 - u) * inv % a2
    return u + v * a1

def f(x0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if x0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)

if x0 == -1:
    print(0)
    sys.exit()

x0 -= T * 10 ** 36

ok = 10 ** 60
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2

    val = x0 + T * mid
    k = (val - b1) // a1
    l = (val - b2) // a2
    if k >= 0 and l >= 0:
        ok = mid
    else:
        ng = mid

x0 += ok * T

# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)

print(ans)

import sys

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def extgcd(a, b):
    if b == 0: return 1, 0
    x, y = extgcd(b, a % b)
    return y, x - a // b * y

def modinv(a, mod):
    if a == 0: return -1
    if gcd(a, mod) != 1: return -1
    return extgcd(a, mod)[0] % mod

def solve(a1, b1, a2, b2):
    if a1 == a2:
        if b1 % a1 == b2 % a2: return b1
        return -1
    u = b1 % a1
    inv = modinv(a1, a2)
    if inv == -1: return -1
    v = (b2 - u) * inv % a2
    return u + v * a1

def f(x0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if x0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)

if x0 == -1:
    print(0)
    sys.exit()

x0 -= T * 10 ** 36

ok = 10 ** 60
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2

    val = x0 + T * mid
    k = (val - b1) // a1
    l = (val - b2) // a2
    if k >= 0 and l >= 0:
        ok = mid
    else:
        ng = mid

x0 += ok * T

# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)

print(ans)

import sys

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def extgcd(a, b):
    if b == 0: return 1, 0
    x, y = extgcd(b, a % b)
    return y, x - a // b * y

def modinv(a, mod):
    if a == 0: return -1
    if gcd(a, mod) != 1: return -1
    return extgcd(a, mod)[0] % mod

def solve(a1, b1, a2, b2):
    u = b1 % a1
    inv = modinv(a1, a2)
    if inv == -1: return -1
    v = (b2 - u) * inv % a2
    return u + v * a1

def f(x0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if x0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)

if x0 == -1:
    print(0)
    sys.exit()

x0 -= T * 10 ** 18

ok = 10 ** 36
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2

    val = x0 + T * mid
    k = (val - b1) // a1
    l = (val - b2) // a2
    if k >= 0 and l >= 0:
        ok = mid
    else:
        ng = mid

x0 += ok * T

# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)

print(ans)

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def extgcd(a, b):
    if b == 0: return 1, 0
    x, y = extgcd(b, a % b)
    return y, x - a // b * y

def modinv(a, mod):
    if a == 0: return -1
    if gcd(a, mod) != 1: return -1
    return extgcd(a, mod)[0] % mod

def solve(a1, b1, a2, b2):
    u = b1 % a1
    inv = modinv(a1, a2)
    if inv == -1: return -1
    v = (b2 - b1) * inv % a2
    return u + v * a1

def f(x0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if x0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)
x0 -= T * 10 ** 18

ok = 10 ** 36
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2

    val = x0 + T * mid
    k = (val - b1) // a1
    l = (val - b2) // a2
    if k >= 0 and l >= 0:
        ok = mid
    else:
        ng = mid

x0 += ok * T

# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)

print(ans)

import sys

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

def extgcd(a, b):
    if b == 0: return 1, 0
    x, y = extgcd(b, a % b)
    return y, x - a // b * y

def modinv(a, mod):
    if a == 0: return -1
    if gcd(a, mod) != 1: return -1
    return extgcd(a, mod)[0] % mod

def solve(a1, b1, a2, b2):
    u = b1 % a1
    inv = modinv(a1, a2)
    if inv == -1: return -1
    v = (b2 - b1) * inv % a2
    return u + v * a1

def f(x0, T, v):
    ok = 10 ** 36
    ng = -1

    while ok - ng > 1:
        mid = (ok + ng) // 2

        if x0 + T * mid >= v:
            ok = mid
        else:
            ng = mid

    return ok

a1, b1, a2, b2, L, R = map(int, input().split())

T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)

if x0 == -1:
    print(0)
    sys.exit()

x0 -= T * 10 ** 18

ok = 10 ** 36
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2

    val = x0 + T * mid
    k = (val - b1) // a1
    l = (val - b2) // a2
    if k >= 0 and l >= 0:
        ok = mid
    else:
        ng = mid

x0 += ok * T

# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)

print(ans)

from fractions import gcd
def egcd(a, b):
    if a == 0:
        return [0, 1]
    if b == 0:
        return [1, 0]
    p = egcd(b%a, a)
    x = p[0]; y = p[1]
    return [y-x*(b//a), x]

def solve(a1, m1, a2, m2):
    sol = egcd(m1, m2)
    m1x = m1 * sol[0]
    m2y = m2 * sol[1]
    return (m1x*a2+m2y*a1)

a1, b1, a2, b2, L, R = map(int, input().split(' '))
L -= b1; R -= b1; b2 -= b1; b1 = 0;
g = gcd(a1, a2)
L = max(L, max(b1, b2))
if (b2%g != 0 or L > R):
    print(0)
    quit()
rmod = a1 * a2 // g;
a1 //= g; b2 //= g; a2 //= g;
sol = solve(b1, a1, b2, a2);
mod = a1 * a2;
sol %= mod; sol *= g;
L -= sol; R -= sol;
if (L <= 0):
    lnew = L%rmod; R += lnew - L; L = lnew;
print(R//rmod - (L-1)//rmod - 1)


import sys

def calc(n, m):
    return ((n+1)/2)*((m+1)/2)+(m/2)*(n/2)

nn, mm = map(int, sys.stdin.readline().split())
x = int(sys.stdin.readline())

n = nn-2*(x-1)
m = mm-2*(x-1)

if n <= 0 or m <= 0:
    print 0
else:
    res = calc(n, m)
    if n-2 > 0 and m-2 > 0:
        res -= calc(n-2, m-2)
    print res

n, m = map(int, input().split())
x = int(input())
a = max(0, n - 2 * (x - 1))
b = max(0, m - 2 * (x - 1))
size = a * b - max(0, a - 2) * max(0, b - 2)
result = (size + 1) // 2
print(result)

n,m=map(int,input().split())
x=int(input())
w,h=n-(2*x-1),m-(2*x-1)
if w<0 or h<0:
    print(0)
else:
    print(max(w+h,1))

import math
a=list(map(int,input().split()))
x=int(input())
bt=math.ceil((a[0]*a[1])/2)
c=[]
if a[0]>=2 and a[1]>=2:
    k=(math.ceil(a[0]/2)+math.floor(a[0]/2)+math.ceil((a[1]-2)/2)+math.floor((a[1]-2)/2))
else:
    k=math.ceil(max(a)/2)+math.floor(max(a)/2)
while True:
    if a[0]<2 or a[1]<2:
        c.append(k)
        break
    c.append(k)
    a[0]-=2
    a[1]-=2
    if a[0]>=2 and a[1]>=2:
        k=(math.ceil(a[0]/2)+math.floor(a[0]/2)+math.ceil((a[1]-2)/2)+math.floor((a[1]-2)/2))
    else:
        k=math.ceil(max(a)/2)+math.floor(max(a)/2)
if x-1>len(c):
    print('0')
else:
    print(c[x-1])

import itertools
import math

n, m = [int(k) for k in input().split()]
x = int(input())
if n-2*(x-1) < 1 or m-2*(x-1) < 1:
    print(0)
elif n-2*(x-1) == 1 or m-2*(x-1) == 1:
    print((n+m-4*(x-1))//2)
else: print(n+m-2 - 4*(x-1))

# Made By Mostafa_Khaled

#! /usr/bin/env python
from sys import stdin, setrecursionlimit as depth

depth(10000)

def count_black(length,init):
	if length<0:
		return 0
	if init: #black
		ret=length/2
		if length%2:
			ret+=1
	else:
		ret=length/2
	return ret

def paint(n,m,x,step):
	#print n,m,x,step
	if n<=0 or m<=0:
		return 0
	elif x==1:
		if n==1:
			return count_black(m,True)
		elif m==1:
			return count_black(n,True)
		else:
			top_row=count_black(m,True)
			bottom_row=count_black(m,((n-1)%2==0))
			left_col=count_black(n-2,False)
			right_black=((n+m-1)%2)==0
			right_col=count_black(n-2,right_black)
			#print ">>> %d %d %d %d"%(top_row,bottom_row,left_col,right_col)
			return sum((top_row,bottom_row,left_col,right_col))
	else:
		return paint(n-2,m-2,x-1,step+1)

if __name__=='__main__':
	n,m=map(int,stdin.readline().split())
	x=int(stdin.readline())
	print paint(n,m,x,0)

n,m=map(int,raw_input().split())
x=input()-1
print max(n+m-4*x-2,1) if min(n,m)>2*x else 0

n, m = map(int, raw_input().split())
x = input()
b = lambda h, w: ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2) if h > 0 and w > 0 else 0
h, w = n - x - x, m - x - x
print b(h + 2, w + 2) - b(h, w)

import math

n, m = map(int, raw_input().split())
x = int(raw_input()) - 1

a = n - (x*2)
b = m - (x*2)

if a > 0 and b > 0:
    if a == b == 1:
        print 1
    else:
        if a == 1:
            print int(math.ceil(b/2))
        elif b == 1:
            print int(math.ceil(a/2))
        else: print (2*a + 2*(b-2))/2
else:
    print 0

n, m = map(int, raw_input().split())
x = input()
def black(x1, y1, x2, y2):
  if x1 > x2 or y1 > y2:
    return 0
  h, w = x2 - x1 + 1, y2 - y1 + 1
  return ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2)
if min(n, m) >= x + x - 1:
  print black(x - 1, x - 1, n - x, m - x) - black(x, x, n - x - 1, m - x - 1)
else:
  print 0

n, m = map(int, raw_input().split())
x = input()
def black(x1, y1, x2, y2):
  if x1 > x2 or y1 > y2:
    return 0
  h, w = x2 - x1 + 1, y2 - y1 + 1
  return ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2)
print black(x - 1, x - 1, n - x, m - x) - black(x, x, n - x - 1, m - x - 1)

from itertools import *
[n, m], x = map (int, raw_input ().split ()), input ()
n -= (x - 1) * 2
m -= (x - 1) * 2
n, m = sorted ([n, m])
if [n, m] == [1, 1]:
    p = 1
elif n == 1:
    p = (m + 1) / 2
elif n > 0 and m > 0:
    p = ((n + m) * 2 - 4) / 2
else:
    p = 0
print p

def sqr(x,y): return 0 if x<1 or y<1 else x*y
x,y = map(int,raw_input().split())
i = input()
print (sqr(x-2*(i-1), y-2*(i-1))-sqr(x-2*i, y-2*i)+1)/2

buf = raw_input()

[n,m] = [int(i) for i in buf.split()]

x = int(raw_input()) - 1

n2 = n - 2*x
m2 = m - 2*x

if n2 <= 0 or m2 <= 0:
    print 0
elif n2 == 1:
    print (m2+1)/2
elif m2 == 1:
    print (n2+1)/2
else:
    print m2 + n2 - 2

# Codeforces Beta Round #40
# Problem B -- Repaintings
n, m = map(int, raw_input().split())
x = input() - 1
if min(n, m) > 2 * x:
	print max(n + m - 4 * x - 2, 1)
else:
	print 0

n, m = map(int, input().split())
x = int(input())
k = 0
for i in range(n):
    for j in range(m):
        if not (i + j) % 2:
            if min(min(i, j) + 1, min(n - i, m - j)) == x:
                k += 1
print(k)

n , m = map(int , raw_input().split())
x = int(raw_input())

def change():
    global n , m
    n -= 2
    m -= 2
    n = max(n , 0)
    m = max(m , 0)

def calc(n , m):
    ret = 0
    for i in range(1 , n+1):
        ret += m/2
        if m%2 == 1:
            ret += (i&1)
    return ret

for i in range(1 , min(x , 10000)):
    change()
ans = calc(n , m)
change()
ans -= calc(n , m)
print(ans)

n,m = map(int,raw_input().split())
x = input()
print 0 if n<=2*x-2 or m<=2*x-2 else max(n+m-4*x+2,1)

n,m = map(int,raw_input().split())
x = input()
n-=2*x-2
m-=2*x-2
if n<=0 or m<=0:
	print 0
elif n==1 and m==1:
	print 1
else:
	print n+m-2

n, m = map(int, raw_input().split())
x = input()
def black(x1, y1, x2, y2):
  h, w = x2 - x1 + 1, y2 - y1 + 1
  return ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2)
if min(n, m) >= x + x - 1:
  print black(x - 1, x - 1, n - x, m - x) - black(x, x, n - x - 1, m - x - 1)
else:
  print 0

n,m=map(int,raw_input().split())
x=input()
if n<m: n,m=m,n
a,b=n-2*(x-1),m-2*(x-1)

print max(0,a+b-2)

n,m=map(int,raw_input().split())
x=input()
if n<m: n,m=m,n
a,b=n-2*(x-1),m-2*(x-1)
if a%2==0: b=b-1
else: b=b-2
a=(a+1)/2
b=(b-1)/2
if b<0:r=a
else: r=2*a+2*b
print r

n , m = map(int , raw_input().split())
x = int(raw_input())

def change():
    global n , m
    if n % 2 == 0:
        n -= 1
    if m % 2 == 0:
        m -= 1
    n -= 2
    m -= 2
    n = max(n , 0)
    m = max(m , 0)

def calc(n , m):
    ret = 0
    for i in range(0 , n):
        for j in range(0 , m):
            if (i + j) % 2 == 0:
                ret += 1
    return ret

for i in range(1 , x):
    change()
ans = calc(n , m)
change()
ans -= calc(n , m)
print(ans)

n , m = map(int , raw_input().split())
x = int(raw_input())

def change():
    global n , m
    n -= 2
    m -= 2
    n = max(n , 0)
    m = max(m , 0)

def calc(n , m):
    ret = 0
    for i in range(1 , n+1):
        ret += m/2 + (i&1)
    return ret

for i in range(1 , min(x , 10000)):
    change()
ans = calc(n , m)
change()
ans -= calc(n , m)
print(ans)

buf = raw_input()

[n,m] = [int(i) for i in buf.split()]

x = int(raw_input()) - 1

res = m + n - 2 - 2 * x

if res > 0:
    print res
else:
    print '0'

buf = raw_input()

[n2,m2] = [(int(i)+1)/2 for i in buf.split()]

x = int(raw_input()) - 1

res = (n2-x)*(m2-x)

if res > 0:
    print res
else:
    print '0'

# Codeforces Beta Round #40
# Problem B -- Repaintings
n, m = map(int, raw_input().split())
x = input() - 1
if min(n, m) > 2 * x:
	print max(n + m - 4 * x, 1)
else:
	print 0

import sys

n, m = map(int, sys.stdin.readline().split())
x = int(sys.stdin.readline())

if n % 2 == 0 and m % 2 == 0:
    if x > min(m, n):
        print "0"
    else:
        print (n-2*(x-1))*((m-2*(x-1))/2)
else:
    if n % 2 == 0:
        n -= 1
    if m % 2 == 0:
        m -= 1

    nn = (n+1)/2
    mm = (m+1)/2

    if x > min(nn, mm)/2+1:
        print "0"
    else:
        nn = (n+1)/2
        mm = (m+1)/2

        print (nn-x+1)*(mm-x+1)

import sys

nn, mm = map(int, sys.stdin.readline().split())
x = int(sys.stdin.readline())

n = nn-2*(x-1)
m = mm-2*(x-1)

if n == 1 and m == 1:
    print 1
elif n <= 0 or m <= 0:
    print 0
else:
    print ((n+1)/2)*(m/2)+((m+1)/2)*(n/2)