from fractions import gcd



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



ok1=b-a+1

a-=1

ng1=b//c-a//c

ng2=b//d-a//d

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

ok2=b//lcm-a//lcm 



print((ok1-ng1-ng2+ok2))
from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

from math import gcd



a,b,c,d=nii()



a_c=(a-1)//c

b_c=b//c



a_d=(a-1)//d

b_d=b//d



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

a_lcm=(a-1)//lcm

b_lcm=b//lcm



print(((b-a+1)-(b_c-a_c)-(b_d-a_d)+(b_lcm-a_lcm)))
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
ok1 = b - a + 1
a -= 1
ng1 = b // c - a // c
ng2 = b // d - a // d
lcm = (c * d) // gcd(c, d)
ok2 = b // lcm - a // lcm
print((ok1 - ng1 - ng2 + ok2))

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from math import gcd

a, b, c, d = nii()
a_c = (a - 1) // c
b_c = b // c
a_d = (a - 1) // d
b_d = b // d
lcm = (c * d) // gcd(c, d)
a_lcm = (a - 1) // lcm
b_lcm = b // lcm
print(((b - a + 1) - (b_c - a_c) - (b_d - a_d) + (b_lcm - a_lcm)))

-from fractions import gcd +from sys import stdin -a, b, c, d = list(map(int, input().split())) -ok1 = b - a + 1 -a -= 1 -ng1 = b // c - a // c -ng2 = b // d - a // d +nii = lambda: list(map(int, stdin.readline().split())) +lnii = lambda: list(map(int, stdin.readline().split())) +from math import gcd + +a, b, c, d = nii() +a_c = (a - 1) // c +b_c = b // c +a_d = (a - 1) // d +b_d = b // d -ok2 = b // lcm - a // lcm -print((ok1 - ng1 - ng2 + ok2)) +a_lcm = (a - 1) // lcm +b_lcm = b // lcm +print(((b - a + 1) - (b_c - a_c) - (b_d - a_d) + (b_lcm - a_lcm)))