import fractions

 

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

 

A -= 1

lcm=C*D // fractions.gcd(C, D)

 

ex = A - (A // C + A // D - A // lcm)

num = B - (B // C + B // D - B // lcm)



print((num-ex))
import math

 

def gcd(a,b):

  while b!=0:

    a,b=b,a%b

  return a

 

def lcm(a,b):

  if a >= b:

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

  else:

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

 

 

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

A -= 1



k1 = A // C

k2 = B // C

k3 = A // D

k4 = B // D

 

k5 = k2 - k1 + 1

k6 = k4 - k3 + 1

 

lcm_num = lcm(C, D)

k7 = A // lcm_num

k8 = B // lcm_num

 

k9 = k8 - k7 + 1

 

print((B - A + 1 - k5 - k6 + k9))
import fractions

A, B, C, D = list(map(int, input().split()))
A -= 1
lcm = C * D // fractions.gcd(C, D)
ex = A - (A // C + A // D - A // lcm)
num = B - (B // C + B // D - B // lcm)
print((num - ex))

import math


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


def lcm(a, b):
    if a >= b:
        return a * b // gcd(a, b)
    else:
        return a * b // gcd(b, a)


A, B, C, D = list(map(int, input().split()))
A -= 1
k1 = A // C
k2 = B // C
k3 = A // D
k4 = B // D
k5 = k2 - k1 + 1
k6 = k4 - k3 + 1
lcm_num = lcm(C, D)
k7 = A // lcm_num
k8 = B // lcm_num
k9 = k8 - k7 + 1
print((B - A + 1 - k5 - k6 + k9))

-import fractions +import math + + +def gcd(a, b): +    while b != 0: +        a, b = b, a % b +    return a + + +def lcm(a, b): +    if a >= b: +        return a * b // gcd(a, b) +    else: +        return a * b // gcd(b, a) + -lcm = C * D // fractions.gcd(C, D) -ex = A - (A // C + A // D - A // lcm) -num = B - (B // C + B // D - B // lcm) -print((num - ex)) +k1 = A // C +k2 = B // C +k3 = A // D +k4 = B // D +k5 = k2 - k1 + 1 +k6 = k4 - k3 + 1 +lcm_num = lcm(C, D) +k7 = A // lcm_num +k8 = B // lcm_num +k9 = k8 - k7 + 1 +print((B - A + 1 - k5 - k6 + k9))