import math

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

count=b-a+1



A=a-1

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

acou=(A//c)+(A//d)-int((A//l))

bcou=(b//c)+(b//d)-int((b//l))



print((count-(bcou-acou)))
import math

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

count=b-a+1

acou=((a-1)//c)+((a-1)//d)-int(((a-1)//(c*d//math.gcd(c,d))))

bcou=(b//c)+(b//d)-int((b//(c*d//math.gcd(c,d))))

print((count-(bcou-acou)))

import math

a, b, c, d = list(map(int, input().split()))
count = b - a + 1
A = a - 1
l = c * d // math.gcd(c, d)
acou = (A // c) + (A // d) - int((A // l))
bcou = (b // c) + (b // d) - int((b // l))
print((count - (bcou - acou)))

import math

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

-A = a - 1 -l = c * d // math.gcd(c, d) -acou = (A // c) + (A // d) - int((A // l)) -bcou = (b // c) + (b // d) - int((b // l)) +acou = ((a - 1) // c) + ((a - 1) // d) - int(((a - 1) // (c * d // math.gcd(c, d)))) +bcou = (b // c) + (b // d) - int((b // (c * d // math.gcd(c, d))))