#二回目

import fractions

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

def lcm(x, y):

    return (x * y) // fractions.gcd(x, y)





ans1=b

a-=1

ans2=0

ans1-=b//c

ans1-=b//d



ans1+=b//(lcm(c,d))

#print(ans1)



ans2+=a//c

ans2+=a//d

ans2-=a//(lcm(c,d))

print((ans1-(a-ans2)))
import math

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



def lcm(x, y):

    return (x * y) // math.gcd(x, y)

a-=1

e=lcm(c,d)



ansb=0

ansb += b//c

ansb += b//d

ansb -= b//e







ansa=0

ansa += a//c

ansa += a//d

ansa -= a//e

print(((b-a)-(ansb-ansa)))
# 二回目
import fractions

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


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


ans1 = b
a -= 1
ans2 = 0
ans1 -= b // c
ans1 -= b // d
ans1 += b // (lcm(c, d))
# print(ans1)
ans2 += a // c
ans2 += a // d
ans2 -= a // (lcm(c, d))
print((ans1 - (a - ans2)))

import math

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


a -= 1
e = lcm(c, d)
ansb = 0
ansb += b // c
ansb += b // d
ansb -= b // e
ansa = 0
ansa += a // c
ansa += a // d
ansa -= a // e
print(((b - a) - (ansb - ansa)))

-# 二回目 -import fractions +import math -    return (x * y) // fractions.gcd(x, y) +    return (x * y) // math.gcd(x, y) -ans1 = b -ans2 = 0 -ans1 -= b // c -ans1 -= b // d -ans1 += b // (lcm(c, d)) -# print(ans1) -ans2 += a // c -ans2 += a // d -ans2 -= a // (lcm(c, d)) -print((ans1 - (a - ans2))) +e = lcm(c, d) +ansb = 0 +ansb += b // c +ansb += b // d +ansb -= b // e +ansa = 0 +ansa += a // c +ansa += a // d +ansa -= a // e +print(((b - a) - (ansb - ansa)))