import fractions



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



def div(a,c,d):

    ac=a//c

    ad=a//d

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

    acd=a//cd

    return ac+ad-acd



ans=B-(A-1)-(div(B,C,D)-div(A-1,C,D))

print(ans)
import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    a,b,c,d=MI()

    cc=b//c - (a-1)//c

    dd=b//d - (a-1)//d

    

    import math

    g=(c*d)//math.gcd(c,d)

    gg=b//g - (a-1)//g

    

    print((b-a+1 -cc-dd+gg))



main()

import fractions

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


def div(a, c, d):
    ac = a // c
    ad = a // d
    cd = c * d // fractions.gcd(c, d)
    acd = a // cd
    return ac + ad - acd


ans = B - (A - 1) - (div(B, C, D) - div(A - 1, C, D))
print(ans)

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    a, b, c, d = MI()
    cc = b // c - (a - 1) // c
    dd = b // d - (a - 1) // d
    import math

    g = (c * d) // math.gcd(c, d)
    gg = b // g - (a - 1) // g
    print((b - a + 1 - cc - dd + gg))


main()

-import fractions +import sys -A, B, C, D = list(map(int, input().split())) +input = sys.stdin.readline -def div(a, c, d): -    ac = a // c -    ad = a // d -    cd = c * d // fractions.gcd(c, d) -    acd = a // cd -    return ac + ad - acd +def I(): +    return int(eval(input())) -ans = B - (A - 1) - (div(B, C, D) - div(A - 1, C, D)) -print(ans) +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def main(): +    mod = 10**9 + 7 +    a, b, c, d = MI() +    cc = b // c - (a - 1) // c +    dd = b // d - (a - 1) // d +    import math + +    g = (c * d) // math.gcd(c, d) +    gg = b // g - (a - 1) // g +    print((b - a + 1 - cc - dd + gg)) + + +main()