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



from fractions import gcd

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

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



a_num = (a-1)//c + (a-1)//d - (a-1)//lcm

b_num = (b)//c + (b)//d - (b)//lcm



print((b-a+1 - (b_num - a_num)))
a, b, c, d = list(map(int, input().split()))



from fractions import gcd

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

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



a_num = (a-1)//c + (a-1)//d - (a-1)//lcm

b_num = (b)//c + (b)//d - (b)//lcm



print((b-a+1 - (b_num - a_num)))
a, b, c, d = list(map(int, input().split()))
from fractions import gcd

# lcm = c * d // gcd(c, d)
lcm = int(c * d / gcd(c, d))
a_num = (a - 1) // c + (a - 1) // d - (a - 1) // lcm
b_num = (b) // c + (b) // d - (b) // lcm
print((b - a + 1 - (b_num - a_num)))

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

lcm = c * d // gcd(c, d)
# lcm = int(c * d / gcd(c, d))
a_num = (a - 1) // c + (a - 1) // d - (a - 1) // lcm
b_num = (b) // c + (b) // d - (b) // lcm
print((b - a + 1 - (b_num - a_num)))

-# lcm = c * d // gcd(c, d) -lcm = int(c * d / gcd(c, d)) +lcm = c * d // gcd(c, d) +# lcm = int(c * d / gcd(c, d))