import fractions

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

g=fractions.gcd(c,d)

l=c*d//g

print((b-b//c-b//d+b//l-(a-1-(a-1)//c-(a-1)//d+(a-1)//l)))
import math as m

A,B,C,D=list(map(int,input().split()))

A-=1

g=C*D//m.gcd(C,D)

x=B//C-A//C

y=B//D-A//D

z=B//g-A//g

print((B-A-x-y+z))
import fractions

a, b, c, d = list(map(int, input().split()))
g = fractions.gcd(c, d)
l = c * d // g
print(
    (
        b
        - b // c
        - b // d
        + b // l
        - (a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // l)
    )
)

import math as m

A, B, C, D = list(map(int, input().split()))
A -= 1
g = C * D // m.gcd(C, D)
x = B // C - A // C
y = B // D - A // D
z = B // g - A // g
print((B - A - x - y + z))

-import fractions +import math as m -a, b, c, d = list(map(int, input().split())) -g = fractions.gcd(c, d) -l = c * d // g -print( -    ( -        b -        - b // c -        - b // d -        + b // l -        - (a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // l) -    ) -) +A, B, C, D = list(map(int, input().split())) +A -= 1 +g = C * D // m.gcd(C, D) +x = B // C - A // C +y = B // D - A // D +z = B // g - A // g +print((B - A - x - y + z))