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



import fractions

#import math

from functools import reduce

def lcm_base(x, y):

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

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



def lcm_list(numbers):

  return reduce(lcm_base, numbers, 1)



l = lcm_base(c, d)



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

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

k = b//l-(a-1)//l

#print(i, j, k)

ans = b-a+1-(i+j-k)

print(ans)

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

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

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



#import fractions

import math

from functools import reduce

def lcm_base(x, y):

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

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



l = lcm_base(c, d)



r = b//l-(a-1)//l



#print(s, t, r)



ans = b-a+1-(s+t-r)

print(ans)

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

# import math
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
    # return (x * y) // math.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


l = lcm_base(c, d)
i = b // c - (a - 1) // c
j = b // d - (a - 1) // d
k = b // l - (a - 1) // l
# print(i, j, k)
ans = b - a + 1 - (i + j - k)
print(ans)

a, b, c, d = list(map(int, input().split()))
s = b // c - (a - 1) // c
t = b // d - (a - 1) // d
# import fractions
import math
from functools import reduce


def lcm_base(x, y):
    # return (x * y) // fractions.gcd(x, y)
    return (x * y) // math.gcd(x, y)


l = lcm_base(c, d)
r = b // l - (a - 1) // l
# print(s, t, r)
ans = b - a + 1 - (s + t - r)
print(ans)

-import fractions - -# import math +s = b // c - (a - 1) // c +t = b // d - (a - 1) // d +# import fractions +import math -    return (x * y) // fractions.gcd(x, y) -    # return (x * y) // math.gcd(x, y) - - -def lcm_list(numbers): -    return reduce(lcm_base, numbers, 1) +    # return (x * y) // fractions.gcd(x, y) +    return (x * y) // math.gcd(x, y) -i = b // c - (a - 1) // c -j = b // d - (a - 1) // d -k = b // l - (a - 1) // l -# print(i, j, k) -ans = b - a + 1 - (i + j - k) +r = b // l - (a - 1) // l +# print(s, t, r) +ans = b - a + 1 - (s + t - r)