import fractions
 
def gcd(a,b):
    return fractions.gcd(a,b)
a,b,c,d = map(int, input().split())

cd = gcd(c,d)
cd = c*d //cd
c_able = b//c - (a-1)//c
d_able = b//d - (a-1)//d
cd_able = b//(cd) - (a-1)//(cd)

print(b- a + 1 - (c_able + d_able - cd_able))