import fractions

import sys

input = sys.stdin.readline# 最小公倍数



def lcm(x, y):

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

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

e = lcm(c, d)

#print("e: {}".format(e))

#print("c: {} - {}".format(b // c, (a - 1) // c))

#print("d: {} - {}".format(b // d, (a - 1) // d))

#print("e: {} - {}".format(b // e, (a - 1) // e))

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

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

count_e = b // e - (a - 1) // e

# b - a の中から d の倍数の個数を取得

#print("count_c: {}".format(count_c))

#print("count_d: {}".format(count_d))

#print("count_e: {}".format(count_e))

print((b - a + 1 - (count_c + count_d - count_e)))
import sys

import math



input = sys.stdin.readline# 最小公倍数

 

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a



def lcm(x, y):

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

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

e = lcm(c, d)

#print("e: {}".format(e))

#print("c: {} - {}".format(b // c, (a - 1) // c))

#print("d: {} - {}".format(b // d, (a - 1) // d))

#print("e: {} - {}".format(b // e, (a - 1) // e))

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

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

count_e = b // e - (a - 1) // e

# b - a の中から d の倍数の個数を取得

#print("count_c: {}".format(count_c))

#print("count_d: {}".format(count_d))

#print("count_e: {}".format(count_e))

print((b - a + 1 - (count_c + count_d - count_e)))
import fractions
import sys

input = sys.stdin.readline  # 最小公倍数


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


a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
# print("e: {}".format(e))
# print("c: {} - {}".format(b // c, (a - 1) // c))
# print("d: {} - {}".format(b // d, (a - 1) // d))
# print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
# print("count_c: {}".format(count_c))
# print("count_d: {}".format(count_d))
# print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))

import sys
import math

input = sys.stdin.readline  # 最小公倍数


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


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


a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
# print("e: {}".format(e))
# print("c: {} - {}".format(b // c, (a - 1) // c))
# print("d: {} - {}".format(b // d, (a - 1) // d))
# print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
# print("count_c: {}".format(count_c))
# print("count_d: {}".format(count_d))
# print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))

-import fractions +import math +def gcd(a, b): +    while b: +        a, b = b, a % b +    return a + + -    return (x * y) // fractions.gcd(x, y) +    return (x * y) // gcd(x, y)