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

from fractions import gcd



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



num_b_c = b//c

num_b_d = b//d

num_b_cd = b//lcm



if a%c==0:

    num_a_c = a//c - 1

else:

    num_a_c = a//c



if a%d==0:

    num_a_d = a//d - 1

else:

    num_a_d = a//d



if a%lcm==0:

    num_a_cd = a//lcm - 1 

else:



    num_a_cd = a//lcm





alls = b - a + 1





c_div = num_b_c - num_a_c

d_div = num_b_d - num_a_d



cd_div = num_b_cd -num_a_cd





print((alls - ( c_div + d_div - cd_div)))



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



from math import gcd



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



b_div_c = b//c

a_div_c = (a-1)//c



b_div_d =b//d

a_div_d = (a-1)//d



b_div_cd = b//lcm

a_div_cd = (a-1)//lcm







ans1 = b_div_c - a_div_c

ans2 = b_div_d - a_div_d

ans3 = b_div_cd - a_div_cd



ans = b -(a-1) - ans1 - ans2 + ans3

print(ans)
a, b, c, d = list(map(int, input().split()))
from fractions import gcd

lcm = c * d // gcd(c, d)
num_b_c = b // c
num_b_d = b // d
num_b_cd = b // lcm
if a % c == 0:
    num_a_c = a // c - 1
else:
    num_a_c = a // c
if a % d == 0:
    num_a_d = a // d - 1
else:
    num_a_d = a // d
if a % lcm == 0:
    num_a_cd = a // lcm - 1
else:
    num_a_cd = a // lcm
alls = b - a + 1
c_div = num_b_c - num_a_c
d_div = num_b_d - num_a_d
cd_div = num_b_cd - num_a_cd
print((alls - (c_div + d_div - cd_div)))

a, b, c, d = list(map(int, input().split()))
from math import gcd

lcm = (c * d) // gcd(c, d)
b_div_c = b // c
a_div_c = (a - 1) // c
b_div_d = b // d
a_div_d = (a - 1) // d
b_div_cd = b // lcm
a_div_cd = (a - 1) // lcm
ans1 = b_div_c - a_div_c
ans2 = b_div_d - a_div_d
ans3 = b_div_cd - a_div_cd
ans = b - (a - 1) - ans1 - ans2 + ans3
print(ans)

-from fractions import gcd +from math import gcd -lcm = c * d // gcd(c, d) -num_b_c = b // c -num_b_d = b // d -num_b_cd = b // lcm -if a % c == 0: -    num_a_c = a // c - 1 -else: -    num_a_c = a // c -if a % d == 0: -    num_a_d = a // d - 1 -else: -    num_a_d = a // d -if a % lcm == 0: -    num_a_cd = a // lcm - 1 -else: -    num_a_cd = a // lcm -alls = b - a + 1 -c_div = num_b_c - num_a_c -d_div = num_b_d - num_a_d -cd_div = num_b_cd - num_a_cd -print((alls - (c_div + d_div - cd_div))) +lcm = (c * d) // gcd(c, d) +b_div_c = b // c +a_div_c = (a - 1) // c +b_div_d = b // d +a_div_d = (a - 1) // d +b_div_cd = b // lcm +a_div_cd = (a - 1) // lcm +ans1 = b_div_c - a_div_c +ans2 = b_div_d - a_div_d +ans3 = b_div_cd - a_div_cd +ans = b - (a - 1) - ans1 - ans2 + ans3 +print(ans)