from fractions import gcd

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

e = c*d//gcd(c,d)

a -= 1



A = b - (b//c + b//d -  b//e)

B = a - (a//c + a//d - a//e)

print((A-B))
import math

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

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

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

x = c*d//math.gcd(c,d)

CD = b//x - (a-1)//x

print(((b-a+1) - (C+D-CD)))
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
e = c * d // gcd(c, d)
a -= 1
A = b - (b // c + b // d - b // e)
B = a - (a // c + a // d - a // e)
print((A - B))

import math

a, b, c, d = list(map(int, input().split()))
C = b // c - (a - 1) // c
D = b // d - (a - 1) // d
x = c * d // math.gcd(c, d)
CD = b // x - (a - 1) // x
print(((b - a + 1) - (C + D - CD)))

-from fractions import gcd +import math -e = c * d // gcd(c, d) -a -= 1 -A = b - (b // c + b // d - b // e) -B = a - (a // c + a // d - a // e) -print((A - B)) +C = b // c - (a - 1) // c +D = b // d - (a - 1) // d +x = c * d // math.gcd(c, d) +CD = b // x - (a - 1) // x +print(((b - a + 1) - (C + D - CD)))