import fractions



def lcm(x, y):

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



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



x = (b//c - (a-1)//c) + (b//d - (a-1)//d -(b//lcm(c,d)) + (a-1)//lcm(c,d))

print((b-a+1-x))

import sys

input = sys.stdin.readline





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





import fractions

def lcm(x, y):

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





def f(d):

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





def main():

    ans = (B-A+1) - f(C) - f(D) + f(lcm(C, D))

    print(ans)





if __name__ == '__main__':

    main()

import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


a, b, c, d = list(map(int, input().split()))
x = (b // c - (a - 1) // c) + (
    b // d - (a - 1) // d - (b // lcm(c, d)) + (a - 1) // lcm(c, d)
)
print((b - a + 1 - x))

import sys

input = sys.stdin.readline
A, B, C, D = list(map(int, input().split()))
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def f(d):
    return B // d - (A - 1) // d


def main():
    ans = (B - A + 1) - f(C) - f(D) + f(lcm(C, D))
    print(ans)


if __name__ == "__main__":
    main()

+import sys + +input = sys.stdin.readline +A, B, C, D = list(map(int, input().split())) -a, b, c, d = list(map(int, input().split())) -x = (b // c - (a - 1) // c) + ( -    b // d - (a - 1) // d - (b // lcm(c, d)) + (a - 1) // lcm(c, d) -) -print((b - a + 1 - x)) +def f(d): +    return B // d - (A - 1) // d + + +def main(): +    ans = (B - A + 1) - f(C) - f(D) + f(lcm(C, D)) +    print(ans) + + +if __name__ == "__main__": +    main()