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



# b = qa + r

b = C

a = D

r = C%D

while r != 0:

    b = a

    a = r

    r = b%a

gcd = a

CDlcm = C*D//gcd



total = B-(A-1)

Cmuls = B//C - (A-1)//C

Dmuls = B//D - (A-1)//D

CDmuls = B//CDlcm - (A-1)//CDlcm

ans = total - Cmuls - Dmuls + CDmuls

print(ans)

import fractions

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



## b = qa + r

#b = C

#a = D

#r = C%D

#while r != 0:

#    b = a

#    a = r

#    r = b%a

#gcd = a

gcd = fractions.gcd(C, D)

CDlcm = C*D//gcd



total = B-(A-1)

Cmuls = B//C - (A-1)//C

Dmuls = B//D - (A-1)//D

CDmuls = B//CDlcm - (A-1)//CDlcm

ans = total - Cmuls - Dmuls + CDmuls

print(ans)

A, B, C, D = list(map(int, input().split()))
# b = qa + r
b = C
a = D
r = C % D
while r != 0:
    b = a
    a = r
    r = b % a
gcd = a
CDlcm = C * D // gcd
total = B - (A - 1)
Cmuls = B // C - (A - 1) // C
Dmuls = B // D - (A - 1) // D
CDmuls = B // CDlcm - (A - 1) // CDlcm
ans = total - Cmuls - Dmuls + CDmuls
print(ans)

import fractions

A, B, C, D = list(map(int, input().split()))
## b = qa + r
# b = C
# a = D
# r = C%D
# while r != 0:
#    b = a
#    a = r
#    r = b%a
# gcd = a
gcd = fractions.gcd(C, D)
CDlcm = C * D // gcd
total = B - (A - 1)
Cmuls = B // C - (A - 1) // C
Dmuls = B // D - (A - 1) // D
CDmuls = B // CDlcm - (A - 1) // CDlcm
ans = total - Cmuls - Dmuls + CDmuls
print(ans)

+import fractions + -# b = qa + r -b = C -a = D -r = C % D -while r != 0: -    b = a -    a = r -    r = b % a -gcd = a +## b = qa + r +# b = C +# a = D +# r = C%D +# while r != 0: +#    b = a +#    a = r +#    r = b%a +# gcd = a +gcd = fractions.gcd(C, D)