from fractions import gcd

from decimal import *



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

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

print((int(b - a + 1 - ((b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e)))))
from fractions import gcd

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

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

print((int(b - a + 1 - ((b // c + b // d - b // e) - ((a - 1) // c + (a - 1) // d - (a - 1) // e)))))
from fractions import gcd
from decimal import *

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

from fractions import gcd

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

-from decimal import * -a, b, c, d = list(map(Decimal, input().split())) -e = c * d / gcd(c, d) +a, b, c, d = list(map(int, input().split())) +e = c * d // gcd(c, d)