import fractions

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



def lcm(x,y):

    return (x*y)//fractions.gcd(x,y)



ans=(b-a+1)-(b//c)+((a-1)//c)-(b//d)+((a-1)//d)+(b//lcm(c,d))-((a-1)//lcm(c,d))

print(ans)
import fractions

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

a-=1

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

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

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


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


ans = (
    (b - a + 1)
    - (b // c)
    + ((a - 1) // c)
    - (b // d)
    + ((a - 1) // d)
    + (b // lcm(c, d))
    - ((a - 1) // lcm(c, d))
)
print(ans)

import fractions

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

- - -def lcm(x, y): -    return (x * y) // fractions.gcd(x, y) - - -ans = ( -    (b - a + 1) -    - (b // c) -    + ((a - 1) // c) -    - (b // d) -    + ((a - 1) // d) -    + (b // lcm(c, d)) -    - ((a - 1) // lcm(c, d)) -) -print(ans) +a -= 1 +e = c * d // fractions.gcd(c, d) +print((b - a - b // c + a // c - b // d + a // d + b // e - a // e))