CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(eval(input()))
mis = lambda: list(map(int, input().split()))
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print((0))
    else:
        ans = -1
        pos = 0
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        while True:
            pos += d1
            if pos == 0:
                ans += 1
                break
            elif pos < 0:
                break
            else:
                ans += 1
            pos += d2
            ans += 1
        print(ans)




main()


# Optimized solution
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(eval(input()))
mis = lambda: list(map(int, input().split()))
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    T1,T2 = mis()
    A1,A2 = mis()
    B1,B2 = mis()
    d1 = T1*A1 - T1*B1
    d2 = T2*A2 - T2*B2
    if d1 + d2 == 0:
        print('infinity')
    elif d1 < 0 > d2 or d1 > 0 < d2:
        print((0))
    else:
        if d1 < 0:
            d1 *= -1
            d2 *= -1
        if d1 + d2 > 0:
            print((0))
        elif d1 % (d1+d2) == 0:
            print((d1 // abs(d1+d2) * 2))
        else:
            print((d1 // abs(d1+d2) * 2 + 1))




main()
# Original solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2

if dis1 > 0:
    dis1 = -dis1
    dis2 = -dis2

if dis1 + dis2 <0:
    print((0))

elif dis1 == -dis2:
    print("infinity")
    
else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print((abs(ans)))
 

# Optimized solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2

if dis1 > 0:
    dis1 = -dis1
    dis2 = -dis2

"""
if dis1 + dis2 <0:
    print(0)

elif dis1 == -dis2:
    print("infinity")
"""

if dis1 + dis2 == 0:
    print("infinity")

elif dis1+dis2 < 0:
    print((0))

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print((abs(ans)))
# Original solution
def sign(x):
    if x==0:
        return 0
    else:
        return abs(x)//x
def flag(x,y):
    return sign(x)==sign(y)
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
if A1*T1+A2*T2==B1*T1+B2*T2:
    print("infinity")
    exit()
ans=0
X=(B1-A1)*T1
Y=(B2-A2)*T2
tmp=0
while(1):
    if tmp==0:
        tmp+=X
    else:
        if not(flag(tmp,tmp+X)):
            ans+=1
            tmp+=X
    if tmp==0:
        tmp+=Y
    else:
        if not(flag(tmp,tmp+Y)):
            ans+=1
            tmp+=Y
    if flag(tmp,tmp+X) and flag(tmp+X,tmp+X+Y):
        break
print(ans)

# Optimized solution
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
X=(B1-A1)*T1
Y=(B2-A2)*T2
if X>0:
    X=-X
    Y=-Y
if X+Y<0:
    print((0))
elif X+Y==0:
    print("infinity")
else:
    A=(-X)//(X+Y)
    B=(-X)%(X+Y)
    if B!=0:
        print((2*A+1))
    else:
        print((2*A))
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    t = LI()
    a = LI()
    b = LI()
    a[0] -= b[0]
    a[1] -= b[1]
    if t[0]*a[0] == -t[1]*a[1]:
        print("infinity")
        return
    if a[0] < 0:
        a[0] *= -1
        a[1] *= -1
    if t[0]*a[0]+t[1]*a[1] > 0:
        print((0))
        return
    l = 0
    r = 10**100
    A = t[0]*a[0]+t[1]*a[1]
    while r-l > 1:
        m = (l+r) >> 1
        x = m*A
        y = x+t[0]*a[0]
        if x*y <= 0:
            l = m
        else:
            r = m
    ans = r*2-1
    if l*A+t[0]*a[0] == 0:
        ans -= 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    t = LI()
    a = LI()
    b = LI()
    a[0] -= b[0]
    a[1] -= b[1]
    if t[0]*a[0] == -t[1]*a[1]:
        print("infinity")
        return
    if a[0] < 0:
        a[0] *= -1
        a[1] *= -1
    if t[0]*a[0]+t[1]*a[1] > 0:
        print((0))
        return
    A = t[0]*a[0]+t[1]*a[1]
    k = t[0]*a[0]
    x = k//(-A)
    ans = 2*x+1
    if A*x+k == 0:
        ans -= 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
            print((2*round(((B1-A1)*T1)/dif)))
        else:
            print((2*k+1))
    else:
        print((0))
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif)))<1e-20:
            print((2*round(((A1-B1)*T1)/abs(dif))))
        else:
            print((2*k+1))
    else:
        print((0))

# Optimized solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
if T1*A1+T2*A2==T1*B1+T2*B2:
    cnt="infinity"
elif T1*A1+T2*A2>T1*B1+T2*B2:
    L = T1*(B1-A1)
    d = T1*A1+T2*A2-(T1*B1+T2*B2)
    if L<0:
        cnt = 0
    elif L==0:
        cnt = 1
    else:
        cnt = 1
        n = L//d
        r = L%d
        if r>0:
            cnt += 2*n
        else:
            cnt += 2*(n-1)+1
elif T1*A1+T2*A2<T1*B1+T2*B2:
    L = T1*(A1-B1)
    d = (T1*B1+T2*B2)-(T1*A1+T2*A2)
    if L<0:
        cnt = 0
    elif L==0:
        cnt = 1
    else:
        cnt = 1
        n = L//d
        r = L%d
        if r>0:
            cnt += 2*n
        else:
            cnt += 2*(n-1)+1
print(cnt)
# Original solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))

len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
  print("infinity")
  quit()

ans = 0
subs = 0  
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)
X = [1, 1]
i = 0
while (X != [0, 0]):
  i += 1
  if subs != 0:
    if subs ** 2 + subs * sub1 <= 0:
      ans += 1
      X[0] = 1
    else:
      X[0] = 0
  subs = subs + sub1
  if subs != 0:
    if subs ** 2 + subs * sub2 <= 0:
      ans += 1
      X[1] = 1
    else:
      X[1] = 0
  subs = subs + sub2

print(ans)
   
    

# Optimized solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))

len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
  print("infinity")
  quit()

ans = 0
subs = 0  
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)

if sub1 > 0:
  if len1 - len2 > 0:
    ans = 0
  else:
    S = (-1 * sub1) // (sub1 + sub2)
    T = (-1 * sub1) % (sub1 + sub2)
    if T == 0:
      ans = 2 * S
    else:
      ans = 2 * S + 1
else:
  if len1 - len2 < 0:
    ans = 0
  else:
    S = (-1 * sub1) // (sub1 + sub2)
    T = (-1 * sub1) % (sub1 + sub2)
    if T == 0:
      ans = 2 * S
    else:
      ans = 2 * S + 1
    
print(ans)
# Original solution
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))

D1 = T1 * (A1 - B1)
D2 = T2 * (A2 - B2)
li = [D1, D2]
li.sort()

pos = 0
cnt = 0
for _ in range(10000000):
  pos += li[0]
  pos1 = pos
  pos += li[1]
  pos2 = pos
  if pos1 < 0 and pos2 >= 0:
    cnt += 2
if cnt >= 1000000:
  print("infinity")
else:
  print((cnt-1))

# Optimized solution
t1, t2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))

if ((a1 - b1) * (a2 - b2) > 0) or (abs(a1 - b1) * t1 > abs(a2 - b2) * t2):
  print((0))
elif abs(a1 - b1) * t1 == abs(a2 - b2) * t2:
  print("infinity")
else:
  d, m = divmod(abs(a1 - b1) * t1, abs(a2 - b2) * t2 - abs(a1 - b1) * t1)
  ans = d * 2
  if m > 0:
    ans += 1
  print(ans)
# Original solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split())) #高橋君
B1,B2 = list(map(int,input().split())) #青木君

# 時間配列
T = [T1]
f = 1
for i in range(3):
    if f:
        Tn = T2
        f = 0
    else:
        Tn = T1
        f = 1
    T.append(T[-1]+Tn)
# print(T)

class runner():
    def __init__(self,v1,v2):
        self.v1 = v1
        self.v2 = v2
        
    def distance(self,t):
        d = t//(T1+T2)*(self.v1*T1 + self.v2*T2)
        tm = t % (T1+T2)
        # print("d",d,"tm",tm)
        if tm < T1:
            d += self.v1 * tm
        else:
            d += self.v2*(tm-T1) + self.v1*T1
        return d

dif = runner(A1-B1,A2-B2)

c = -1
D = 0
DL = [0]
for t in T:
    pD = D
    D = dif.distance(t)
    DL.append(D)
    # print(D)
    if pD*D <= 0:
        c += 1
# print(c)
# print(DL)

if DL[1]*DL[2] > 0:
    print((0))
else:
    if DL[2] == 0:
        print("infinity")
    else:
        a = DL[2]
        if a>0:
            if -DL[1]%a == 0:
                print((-DL[1]//a*2))
            else:
                print((-DL[1]//a*2+1))
        else:
            if -DL[1]%a == 0:
                print((-DL[1]//a*2))
            else:
                print((-DL[1]//a*2+1))

# Optimized solution
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split())) #高橋君
B1,B2 = list(map(int,input().split())) #青木君

D1,D2 = (A1-B1)*T1, (A1-B1)*T1+(A2-B2)*T2

if D1*D2 > 0:
    print((0))
elif D2 == 0:
    print("infinity")
else:
    if -D1%D2 == 0:
        print((-D1//D2*2))
    else:
        print((-D1//D2*2+1))
# Original solution
t,T,a,A,b,B=list(map(int, open(0).read().split()))
x,y=(a-b)*t,(A-B)*T
if x+y==0:
 r="infinity"
else:
 s,t=divmod(-x, x+y)
 r=0 if s<0 else s*2+(1 if t else 0)
print(r)

# Optimized solution
t,T,a,A,b,B=list(map(int, open(0).read().split()))
x,y=(b-a)*t,(A-B)*T
if y-x==0:
 r="infinity"
else:
 s,t=divmod(x,y-x)
 r=max(0,s*2+(1 if t else 0))
print(r)
# Original solution
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return int(gcd(b, c))

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

A, B, C, D = [int(x) for x in input().split()] 

l = lcm(C, D)

A = A-1
x = (B-A)
y = (B//C - A//C)
z = (B//D - A//D)
a = (B//l - A//l)
print((x+a - (y+z)))

# Optimized solution
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b ==  0:
        return a
    r = a % b
    return gcd(b, r) 

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

A, B, C, D = list(map(int, input().split()))

l = lcm(C, D)

A = A-1
N_range = B - A
l_sum = (B//l) - (A//l)
c_sum = (B//C) - (A//C)
d_sum = (B//D) - (A//D)
print((N_range - c_sum - d_sum + l_sum))
# Original solution
# -*-coding: utf-8 -*-

import sys
import math

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

def lcm(x, y):
    return (x * y) // gcd(x, y)

def main():
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().split()))
    a_1 = a - 1
    lcm_cd = lcm(c,d)
    
    a_1_c_count =  a_1 // c
    a_1_d_count =  a_1 // d
    a_lcm_count =  a_1 // lcm_cd

    a_1_result = a_1 - (a_1_c_count + a_1_d_count - a_lcm_count)


    b_c_count = b // c
    b_d_count = b // d
    b_lcm_count = b // lcm_cd

    b_result = (b) - (b_c_count + b_d_count - b_lcm_count)

    result = b_result - a_1_result

    print(result)
    return


if __name__ == '__main__':
    main()

# Optimized solution
import sys

def gcd(a, b):
    """
    最大公約数を求める
    """
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """
    最小公倍数を求める
    """
    return a*b//(gcd(a, b))


input = sys.stdin.readline

a, b, c, d = list(map(int, input().split()))

div_ac = (a-1) // c
div_bc = b // c


div_ad = (a-1) // d
div_bd = b // d

lcm_cd = lcm(c,d)

div_acd = (a-1) // lcm_cd
div_bcd = b // lcm_cd

a_1_result =  div_ac + div_ad - div_acd
b_result = div_bc + div_bd - div_bcd

print(((b+1 - a) - (b_result - a_1_result)))
# Original solution
from math import *
a,b,c,d = list(map(int,input().split()))
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= 0
if f<=b:
  while f<=b:
    if f>=a and f<=b:
      compteur +=1
    f = r*rock
    rock += 1
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0:
  div1+=1
if a%d ==0:
  div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print((mm-roger))

# Optimized solution
from math import *
a,b,c,d = list(map(int,input().split()))
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= (b//f)-(a//f)
if a%f==0:
  compteur +=1
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0:
  div1+=1
if a%d ==0:
  div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print((mm-roger))
# Original solution
import sys

def S(): return sys.stdin.readline().rstrip()

A,B,C,D = list(map(int,S().split()))

from math import gcd

def f(n):  # 1からnまでCでもDでも割り切れない自然数の個数
    return n-n//C-n//D+n//(C*D//gcd(C,D))

print((f(B)-f(A-1)))

# Optimized solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B,C,D = MI()


from math import gcd


def f(n):
    return n-n//C-n//D+n//((C*D)//gcd(C,D))


print((f(B)-f(A-1)))
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B,C,D = MI()


from math import gcd


def f(n):
    return n-n//C-n//D+n//((C*D)//gcd(C,D))


print((f(B)-f(A-1)))


# Optimized solution
import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))


A,B,C,D = MI()

from math import gcd


def f(n):
    return n-n//C-n//D+n//((C*D)//gcd(C,D))


print((f(B)-f(A-1)))
# Original solution
import math
A, B, C, D = list(map(int, input().split()))


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

X = lcm(C, D)

ansB = (B-B//C)+(B-B//D)-(B-B//X)
ansA = ((A-1)-((A-1)//C))+((A-1)-(A-1)//D)-((A-1)-(A-1)//X)

print((ansB-ansA))

# Optimized solution
import math
A, B, C, D = list(map(int, input().split()))
X= (C * D) // math.gcd(C, D)

ansB = (B-B//C)+(B-B//D)-(B-B//X)
ansA = ((A-1)-((A-1)//C))+((A-1)-(A-1)//D)-((A-1)-(A-1)//X)

print((ansB-ansA))
# Original solution
#!/usr/bin/env python3
#ABC131 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)
def lcm(n,m):
    return (n*m)//gcd(n,m)

a,b,c,d = LI()
i,j,k = (a-1)//c,(a-1)//d,(a-1)//lcm(c,d)
s,t,u = b//c,b//d,b//lcm(c,d)
x = b - s - t + u
y = (a-1) - i - j + k
print((x -y))


# Optimized solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a, b, c, d = LI()
ans = b - a + 1
lcm = c * d // math.gcd(c, d)
ans -= b // c - ((a-1) // c + 1) + 1
ans -= b // d - ((a-1) // d + 1) + 1
ans += b // lcm - ((a-1) // lcm + 1) + 1
print(ans)
# Original solution
# -*- coding: utf-8 -*-
'''Snippets for lcm.
Available functions:
- lcm: Compute least common multiple of a and b.
'''


def lcm(a: int, b: int) -> int:
    '''Compute least common multiple of a and b.
    Args:
        a: Int of number (greater than 0).
        b: Int of number (greater than 0).
    Returns:
        least common multiple.
    Landau notation: O(log n)
    See:
    https://gist.github.com/endolith/114336/eff2dc13535f139d0d6a2db68597fad2826b53c3
    https://docs.python.org/3/library/sys.html#sys.version_info
    '''

    from sys import version_info

    if version_info.major == 3 and version_info.minor >= 5:
        from math import gcd
    else:
        from fractions import gcd

    return a * b // gcd(a, b)


def main():
    a, b, c, d = list(map(int, input().split()))
    l = lcm(c, d)
    x = b // c - (a - 1) // c
    y = b // d - (a - 1) // d
    z = b // l - (a - 1) // l
    w = b - a + 1

    if c % d == 0 or d % c == 0:
        print((w - x))
    else:
        print((w - (x + y - z)))


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-
'''Snippets for lcm.
Available functions:
- lcm: Compute least common multiple of a and b.
'''


def lcm(a: int, b: int) -> int:
    '''Compute least common multiple of a and b.
    Args:
        a: Int of number (greater than 0).
        b: Int of number (greater than 0).
    Returns:
        least common multiple.
    Landau notation: O(log n)
    See:
    https://gist.github.com/endolith/114336/eff2dc13535f139d0d6a2db68597fad2826b53c3
    https://docs.python.org/3/library/sys.html#sys.version_info
    '''

    from sys import version_info

    if version_info.major == 3 and version_info.minor >= 5:
        from math import gcd
    else:
        from fractions import gcd

    return a * b // gcd(a, b)


def main():
    a, b, c, d = list(map(int, input().split()))
    l = lcm(c, d)
    x = b // c - (a - 1) // c
    y = b // d - (a - 1) // d
    z = b // l - (a - 1) // l
    w = b - a + 1

    print((w - (x + y - z)))


if __name__ == '__main__':
    main()
# Original solution
a,b,c,d = list(map(int,input().split()))

def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
    
def lcm(x,y):
    return x*y//gcd(x,y)
    
ans = (b-a+1) - (b//c-a//c)- (b//d-a//d) + b//lcm(d,c) - a//lcm(d,c)

if a%c == 0 and a%d != 0:
    ans -=1
elif a%c != 0 and a%d == 0:
    ans -=1
elif a%c == 0 and a%d == 0:
    ans -=1
print(ans)

# Optimized solution
a,b,c,d = list(map(int,input().split()))

def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
    
def lcm(x,y):
    return x*y//gcd(x,y)
    
ans = (b-a+1) - (b//c-(a-1)//c)- (b//d-(a-1)//d) + b//lcm(d,c) - (a-1)//lcm(d,c)
print(ans)
# Original solution
import sys
import math

input = sys.stdin.readline# 最小公倍数
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)    
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))

# Optimized solution
import sys
input = sys.stdin.readline# 最小公倍数
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)    
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
print((b - a + 1 - (count_c + count_d - count_e)))
# Original solution


def gcd(x,y):
    x, y = max(x,y), min(x,y)
    while x!=y :
        x, y = max(x,y), min(x,y)
        x -= y
    return x
#print(gcd(4,8))

a,b,c,d = list(map(int,input().split()))
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d

cd = int(c*d/gcd(c,d))
cd_ok = b//cd - (a-1)//cd

print((int(b-a+1-c_ok-d_ok+cd_ok)))

# Optimized solution


def gcd(x,y):
    x, y = max(x,y), min(x,y)
    while x!=0 :
        x, y = max(x,y), min(x,y)
        x %= y
    return y
#print(gcd(4,8))

a,b,c,d = list(map(int,input().split()))
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d

cd = int(c*d/gcd(c,d))
cd_ok = b//cd - (a-1)//cd

print((int(b-a+1-c_ok-d_ok+cd_ok)))
# Original solution
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

A, B, C, D = list(map(int, input().split()))

CD = C*D//gcd(C, D)

count1 = (B // C - A // C)
count2 = (B // D - A // D)
count3 = (B // CD - A // CD)

if A % C == 0:
    count1 += 1

if A % D == 0:
    count2 += 1

if A % CD == 0:
    count3 += 1 

print((B - A + 1 - ((count1 + count2) - count3)))


# Optimized solution
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

A, B, C, D = list(map(int, input().split()))

CD = C*D//gcd(C, D)

count1 = (B // C - (A - 1) // C)
count2 = (B // D - (A - 1) // D)
count3 = (B // CD - (A - 1) // CD)

print((B - (A - 1) - ((count1 + count2) - count3)))
# Original solution
def gcd(i,j):
  if i > j:
    tmp = i
    i = j
    j = tmp
  while i != 0:
    tmp = i
    i = j%i
    j = tmp
  return j
def lcm(i,j):
  return i*j//gcd(i,j)  
def main():
  a,b,c,d = list(map(int,input().split()))
  ans = b-a+1
  ans -= (b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//lcm(c,d) -(a-1)//lcm(c,d))
  print(ans)


main()


# Optimized solution
#!/usr/bin/env python3
a,b,c,d = list(map(int,input().split()))	
def my_gcd(i,j):
    if i > j: i,j = j,i
    while i != 0:
        if j % i != 0:
            i,j = j%i,i
        else: return i
def not_div(n):
    return b//n  - (a-1) //n
print((not_div(1)-not_div(c)-not_div(d)+not_div(c*d//my_gcd(c,d))))