import fractions

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

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

cnt = b-a+1

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

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

e_cnt = b//e-(a-1)//e

print((cnt-c_cnt-d_cnt+e_cnt))
import fractions

def div_cnt(x):

    return b//x-(a-1)//x



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

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

cnt = b-a+1

c_cnt = div_cnt(c)

d_cnt = div_cnt(d)

e_cnt = div_cnt(e)

print((cnt-c_cnt-d_cnt+e_cnt))
import fractions

a, b, c, d = list(map(int, input().split()))
e = c * d // fractions.gcd(c, d)
cnt = b - a + 1
c_cnt = b // c - (a - 1) // c
d_cnt = b // d - (a - 1) // d
e_cnt = b // e - (a - 1) // e
print((cnt - c_cnt - d_cnt + e_cnt))

import fractions


def div_cnt(x):
    return b // x - (a - 1) // x


a, b, c, d = list(map(int, input().split()))
e = c * d // fractions.gcd(c, d)
cnt = b - a + 1
c_cnt = div_cnt(c)
d_cnt = div_cnt(d)
e_cnt = div_cnt(e)
print((cnt - c_cnt - d_cnt + e_cnt))

+ + +def div_cnt(x): +    return b // x - (a - 1) // x + -c_cnt = b // c - (a - 1) // c -d_cnt = b // d - (a - 1) // d -e_cnt = b // e - (a - 1) // e +c_cnt = div_cnt(c) +d_cnt = div_cnt(d) +e_cnt = div_cnt(e)