import sys

input = sys.stdin.readline

import fractions





def main():

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

    Aone = A - 1

    CDlcm = int(C /  fractions.gcd(C, D) * D)



    Bc = B // C

    Bd = B // D

    Blcm = B // CDlcm

    Bdec = B - Bc - Bd + Blcm



#    print(Bc,Bd,Blcm)



    Ac = Aone // C

    Ad = Aone // D

    Alcm = Aone // CDlcm

    Adec = Aone - Ac - Ad + Alcm



#    print(Ac,Ad,Alcm)



    print((Bdec - Adec))





main()
import sys

 

def gcd(a, b):

    if a < b:

        a, b = b, a

    while b:

        a, b = b, a % b

    return a

 

 

 

def lcm(a, b):

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

 

 

 

def main():

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

    Aone = A - 1

    CDlcm = lcm(C, D)

 

    Bc = B // C

    Bd = B // D

    Blcm = B // CDlcm

    Bdec = B - Bc - Bd + Blcm

 

#    print(Bc,Bd,Blcm)

 

    Ac = Aone // C

    Ad = Aone // D

    Alcm = Aone // CDlcm

    Adec = Aone - Ac - Ad + Alcm

 

#    print(Ac,Ad,Alcm)

 

    print((Bdec - Adec))

 

 

main()
import sys

input = sys.stdin.readline
import fractions


def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    CDlcm = int(C / fractions.gcd(C, D) * D)
    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm
    #    print(Bc,Bd,Blcm)
    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm
    #    print(Ac,Ad,Alcm)
    print((Bdec - Adec))


main()

import sys


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


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


def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    CDlcm = lcm(C, D)
    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm
    #    print(Bc,Bd,Blcm)
    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm
    #    print(Ac,Ad,Alcm)
    print((Bdec - Adec))


main()

-input = sys.stdin.readline -import fractions + +def gcd(a, b): +    if a < b: +        a, b = b, a +    while b: +        a, b = b, a % b +    return a + + +def lcm(a, b): +    return a * b // (gcd(a, b)) -    CDlcm = int(C / fractions.gcd(C, D) * D) +    CDlcm = lcm(C, D)