import fractions

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

total = B - A + 1

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

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

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

CDdiv = B // (cddiv) - (A-1) // (cddiv)

 

print((total - Cdiv - Ddiv + CDdiv))

from fractions import gcd

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



E = (C*D) // gcd(C,D)

x = (A-1) // C

y = (A-1) // D

z = (A-1) // E



xx = B // C

yy = B // D

zz = B // E



Cdiv = xx-x

Ddiv = yy-y

Ediv = zz-z

tmp = xx-x + yy-y - (zz-z)

total = B-A+1

print((int(total - Cdiv - Ddiv + Ediv)))

import fractions

A, B, C, D = list(map(int, input().split()))
total = B - A + 1
Cdiv = B // C - (A - 1) // C
Ddiv = B // D - (A - 1) // D
cddiv = (C * D) // fractions.gcd(C, D)
CDdiv = B // (cddiv) - (A - 1) // (cddiv)
print((total - Cdiv - Ddiv + CDdiv))

from fractions import gcd

A, B, C, D = list(map(int, input().split()))
E = (C * D) // gcd(C, D)
x = (A - 1) // C
y = (A - 1) // D
z = (A - 1) // E
xx = B // C
yy = B // D
zz = B // E
Cdiv = xx - x
Ddiv = yy - y
Ediv = zz - z
tmp = xx - x + yy - y - (zz - z)
total = B - A + 1
print((int(total - Cdiv - Ddiv + Ediv)))

-import fractions +from fractions import gcd +E = (C * D) // gcd(C, D) +x = (A - 1) // C +y = (A - 1) // D +z = (A - 1) // E +xx = B // C +yy = B // D +zz = B // E +Cdiv = xx - x +Ddiv = yy - y +Ediv = zz - z +tmp = xx - x + yy - y - (zz - z) -Cdiv = B // C - (A - 1) // C -Ddiv = B // D - (A - 1) // D -cddiv = (C * D) // fractions.gcd(C, D) -CDdiv = B // (cddiv) - (A - 1) // (cddiv) -print((total - Cdiv - Ddiv + CDdiv)) +print((int(total - Cdiv - Ddiv + Ediv)))