import fractions

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

x=b//c

y=b//d

xy=b//(c*d//fractions.gcd(c,d))

b=b-x-y+xy



x=(a-1)//c

y=(a-1)//d

xy=(a-1)//(c*d//fractions.gcd(c,d))

a=(a-1)-x-y+xy

print((b-a))
import math

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

lcm=(c*d)//math.gcd(c,d)

print(((b-(b//c+b//d-b//lcm))-(a-1-((a-1)//d+(a-1)//c-(a-1)//lcm))))
import fractions

a, b, c, d = list(map(int, input().split()))
x = b // c
y = b // d
xy = b // (c * d // fractions.gcd(c, d))
b = b - x - y + xy
x = (a - 1) // c
y = (a - 1) // d
xy = (a - 1) // (c * d // fractions.gcd(c, d))
a = (a - 1) - x - y + xy
print((b - a))

import math

a, b, c, d = list(map(int, input().split()))
lcm = (c * d) // math.gcd(c, d)
print(
    (
        (b - (b // c + b // d - b // lcm))
        - (a - 1 - ((a - 1) // d + (a - 1) // c - (a - 1) // lcm))
    )
)

-import fractions +import math -x = b // c -y = b // d -xy = b // (c * d // fractions.gcd(c, d)) -b = b - x - y + xy -x = (a - 1) // c -y = (a - 1) // d -xy = (a - 1) // (c * d // fractions.gcd(c, d)) -a = (a - 1) - x - y + xy -print((b - a)) +lcm = (c * d) // math.gcd(c, d) +print( +    ( +        (b - (b // c + b // d - b // lcm)) +        - (a - 1 - ((a - 1) // d + (a - 1) // c - (a - 1) // lcm)) +    ) +)