import fractions

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

N = b-a+1

s = fractions.gcd(c,d)

t = c*d // s

lcm_div = b//t - (a-1)//t

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

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

if c%d==0 or d%c==0:

    w = min(c,d)

    print((N-(b//w-(a-1)//w)))

else:

    print((N-(divc+divd-lcm_div)))
# coding: utf-8

import math

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



e = int(c*d/math.gcd(c,d))



ans = b//c-(a-1)//c#cで

ans += b//d-(a-1)//d#dで

#print(ans)



ans -= b//e-(a-1)//e#両方で

print((int(b-a+1-ans)))
import fractions

a, b, c, d = list(map(int, input().split()))
N = b - a + 1
s = fractions.gcd(c, d)
t = c * d // s
lcm_div = b // t - (a - 1) // t
divc = b // c - (a - 1) // c
divd = b // d - (a - 1) // d
if c % d == 0 or d % c == 0:
    w = min(c, d)
    print((N - (b // w - (a - 1) // w)))
else:
    print((N - (divc + divd - lcm_div)))

# coding: utf-8
import math

a, b, c, d = list(map(int, input().split()))
e = int(c * d / math.gcd(c, d))
ans = b // c - (a - 1) // c  # cで
ans += b // d - (a - 1) // d  # dで
# print(ans)
ans -= b // e - (a - 1) // e  # 両方で
print((int(b - a + 1 - ans)))

-import fractions +# coding: utf-8 +import math -N = b - a + 1 -s = fractions.gcd(c, d) -t = c * d // s -lcm_div = b // t - (a - 1) // t -divc = b // c - (a - 1) // c -divd = b // d - (a - 1) // d -if c % d == 0 or d % c == 0: -    w = min(c, d) -    print((N - (b // w - (a - 1) // w))) -else: -    print((N - (divc + divd - lcm_div))) +e = int(c * d / math.gcd(c, d)) +ans = b // c - (a - 1) // c  # cで +ans += b // d - (a - 1) // d  # dで +# print(ans) +ans -= b // e - (a - 1) // e  # 両方で +print((int(b - a + 1 - ans)))