import fractions

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

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

sum = b-a+1

x = (b//c) - ((a-1)//c)

y = (b//d) - ((a-1)//d)

z = (b//lcm) - ((a-1)//lcm)

n_i = x+y-z

print((int(sum-n_i)))
from fractions import gcd



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



ok1=b-a+1

ng1=b//c-a//c if a%c!=0 else b//c-a//c+1

ng2=b//d-a//d if a%d!=0 else b//d-a//d+1

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

ok2=b//lcm-a//lcm if a%lcm!=0 else b//lcm-a//lcm+1



print((ok1-ng1-ng2+ok2))
import fractions

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

from fractions import gcd

a, b, c, d = list(map(int, input().split()))
ok1 = b - a + 1
ng1 = b // c - a // c if a % c != 0 else b // c - a // c + 1
ng2 = b // d - a // d if a % d != 0 else b // d - a // d + 1
lcm = (c * d) // gcd(c, d)
ok2 = b // lcm - a // lcm if a % lcm != 0 else b // lcm - a // lcm + 1
print((ok1 - ng1 - ng2 + ok2))

-import fractions +from fractions import gcd -lcm = (c * d) // fractions.gcd(c, d) -sum = b - a + 1 -x = (b // c) - ((a - 1) // c) -y = (b // d) - ((a - 1) // d) -z = (b // lcm) - ((a - 1) // lcm) -n_i = x + y - z -print((int(sum - n_i))) +ok1 = b - a + 1 +ng1 = b // c - a // c if a % c != 0 else b // c - a // c + 1 +ng2 = b // d - a // d if a % d != 0 else b // d - a // d + 1 +lcm = (c * d) // gcd(c, d) +ok2 = b // lcm - a // lcm if a % lcm != 0 else b // lcm - a // lcm + 1 +print((ok1 - ng1 - ng2 + ok2))