def main():

    A, B, C, D = list(map(int, input().split()))

    candiv_C = num_can_div(A, B, C)

    candiv_D = num_can_div(A, B, D)

    candiv_lcm = num_can_div(A, B, lcm(C, D))



    print((B-A+1 - candiv_C - candiv_D + candiv_lcm))



def num_can_div(A, B, x):

    return B//x - (A-1)//x



def gcd(a, b):

    while b:

        a, b = b, a % b

    return a



def lcm(a, b):

    return a * b // gcd (a, b)



main()
import fractions as f



A, B, C, D = list(map(int, input().split()))

A = A - 1

lcmCD = C * D // f.gcd(C, D)

underB = B - B // C - B // D + B // lcmCD

underA = A - A // C - A // D + A // lcmCD

print((underB - underA))

def main():
    A, B, C, D = list(map(int, input().split()))
    candiv_C = num_can_div(A, B, C)
    candiv_D = num_can_div(A, B, D)
    candiv_lcm = num_can_div(A, B, lcm(C, D))
    print((B - A + 1 - candiv_C - candiv_D + candiv_lcm))


def num_can_div(A, B, x):
    return B // x - (A - 1) // x


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


main()

import fractions as f

A, B, C, D = list(map(int, input().split()))
A = A - 1
lcmCD = C * D // f.gcd(C, D)
underB = B - B // C - B // D + B // lcmCD
underA = A - A // C - A // D + A // lcmCD
print((underB - underA))

-def main(): -    A, B, C, D = list(map(int, input().split())) -    candiv_C = num_can_div(A, B, C) -    candiv_D = num_can_div(A, B, D) -    candiv_lcm = num_can_div(A, B, lcm(C, D)) -    print((B - A + 1 - candiv_C - candiv_D + candiv_lcm)) +import fractions as f - -def num_can_div(A, B, x): -    return B // x - (A - 1) // x - - -def gcd(a, b): -    while b: -        a, b = b, a % b -    return a - - -def lcm(a, b): -    return a * b // gcd(a, b) - - -main() +A, B, C, D = list(map(int, input().split())) +A = A - 1 +lcmCD = C * D // f.gcd(C, D) +underB = B - B // C - B // D + B // lcmCD +underA = A - A // C - A // D + A // lcmCD +print((underB - underA))