from fractions import gcd

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



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



x = ((a-1)//c)+((a-1)//d)-((a-1)//lcm)

y = (b//c)+(b//d)-(b//lcm)



print(((b-(a-1))-(y-x)))

from math import gcd

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



t = c*d//gcd(c,d)

x = (a-1) - ((a-1)//c + (a-1)//d) + (a-1)//t

y = b - (b//c + b//d) + b//t



print((y-x))
from fractions import gcd

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

from math import gcd

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

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