from fractions import gcd

def floor(a, b):

  # return int((a - a%b)/b)

  return a//b

# def gcd(a, b):

#   while a % b != 0:

#       a, b = b, a % b

#   return a

def lcm(a, b):

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

input = list(map(int, input().split(' ')))

total_count = input[1] + 1 - input[0]

div_c = floor(input[1], input[2]) - floor(input[0] -1, input[2])

div_d = floor(input[1], input[3]) - floor(input[0] -1, input[3])

div_cd = floor(input[1], lcm(input[2], input[3])) - floor(input[0] -1, lcm(input[2], input[3]))

print((total_count - (div_c + div_d - div_cd)))
def floor(a, b):

  # return int((a - a%b)/b)

  return a//b

def gcd(a, b):

  while b != 0:

      a, b = b, a % b

  return a

def lcm(a, b):

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

input = list(map(int, input().split(' ')))

total_count = input[1] + 1 - input[0]

div_c = floor(input[1], input[2]) - floor(input[0] -1, input[2])

div_d = floor(input[1], input[3]) - floor(input[0] -1, input[3])

div_cd = floor(input[1], lcm(input[2], input[3])) - floor(input[0] -1, lcm(input[2], input[3]))

print((total_count - (div_c + div_d - div_cd)))
from fractions import gcd


def floor(a, b):
    # return int((a - a%b)/b)
    return a // b


# def gcd(a, b):
#   while a % b != 0:
#       a, b = b, a % b
#   return a
def lcm(a, b):
    return floor((a * b), gcd(a, b))


input = list(map(int, input().split(" ")))
total_count = input[1] + 1 - input[0]
div_c = floor(input[1], input[2]) - floor(input[0] - 1, input[2])
div_d = floor(input[1], input[3]) - floor(input[0] - 1, input[3])
div_cd = floor(input[1], lcm(input[2], input[3])) - floor(
    input[0] - 1, lcm(input[2], input[3])
)
print((total_count - (div_c + div_d - div_cd)))

def floor(a, b):
    # return int((a - a%b)/b)
    return a // b


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


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


input = list(map(int, input().split(" ")))
total_count = input[1] + 1 - input[0]
div_c = floor(input[1], input[2]) - floor(input[0] - 1, input[2])
div_d = floor(input[1], input[3]) - floor(input[0] - 1, input[3])
div_cd = floor(input[1], lcm(input[2], input[3])) - floor(
    input[0] - 1, lcm(input[2], input[3])
)
print((total_count - (div_c + div_d - div_cd)))

-from fractions import gcd - - -# def gcd(a, b): -#   while a % b != 0: -#       a, b = b, a % b -#   return a +def gcd(a, b): +    while b != 0: +        a, b = b, a % b +    return a + +