import fractions

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

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

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

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

cd = b//gcd - (a-1)//gcd



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

#!/usr/bin/env python3

import sys

import fractions



## 最小公倍数

def lcm(x, y):

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



def solve(A: int, B: int, C: int, D: int):



    # n以下のCでもDでも割り切れない数を返す

    def counter(n):

        c_ct=n//C

        d_ct =n//D

        cd_ct=n//lcm(C,D)

        return n-c_ct-d_ct+cd_ct

    

    print((counter(B)-counter(A-1)))



    return





def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    A = int(next(tokens))  # type: int

    B = int(next(tokens))  # type: int

    C = int(next(tokens))  # type: int

    D = int(next(tokens))  # type: int

    solve(A, B, C, D)



if __name__ == '__main__':

    main()

import fractions

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

#!/usr/bin/env python3
import sys
import fractions

## 最小公倍数
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def solve(A: int, B: int, C: int, D: int):
    # n以下のCでもDでも割り切れない数を返す
    def counter(n):
        c_ct = n // C
        d_ct = n // D
        cd_ct = n // lcm(C, D)
        return n - c_ct - d_ct + cd_ct

    print((counter(B) - counter(A - 1)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == "__main__":
    main()

+#!/usr/bin/env python3 +import sys -a, b, c, d = list(map(int, input().split())) -cc = b // c - (a - 1) // c -dd = b // d - (a - 1) // d -gcd = int(c * d / fractions.gcd(c, d)) -cd = b // gcd - (a - 1) // gcd -print(((b - a + 1) + cd - cc - dd)) +## 最小公倍数 +def lcm(x, y): +    return (x * y) // fractions.gcd(x, y) + + +def solve(A: int, B: int, C: int, D: int): +    # n以下のCでもDでも割り切れない数を返す +    def counter(n): +        c_ct = n // C +        d_ct = n // D +        cd_ct = n // lcm(C, D) +        return n - c_ct - d_ct + cd_ct + +    print((counter(B) - counter(A - 1))) +    return + + +def main(): +    def iterate_tokens(): +        for line in sys.stdin: +            for word in line.split(): +                yield word + +    tokens = iterate_tokens() +    A = int(next(tokens))  # type: int +    B = int(next(tokens))  # type: int +    C = int(next(tokens))  # type: int +    D = int(next(tokens))  # type: int +    solve(A, B, C, D) + + +if __name__ == "__main__": +    main()