from fractions import gcd

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

def f(n):

    x = n//C

    y = n//D

    z = n//(C*D//gcd(C,D))

    return n - x - y + z



print((f(B) - f(A-1)))
a,b,c,d = list(map(int,input().split()))



from math import gcd

def cnt(n):

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

    return n - n//c - n//d + n//lcm

print((cnt(b)-cnt(a-1)))
from fractions import gcd

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


def f(n):
    x = n // C
    y = n // D
    z = n // (C * D // gcd(C, D))
    return n - x - y + z


print((f(B) - f(A - 1)))

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


def cnt(n):
    lcm = c // gcd(c, d) * d
    return n - n // c - n // d + n // lcm


print((cnt(b) - cnt(a - 1)))

-from fractions import gcd - -A, B, C, D = list(map(int, input().split())) +a, b, c, d = list(map(int, input().split())) +from math import gcd -def f(n): -    x = n // C -    y = n // D -    z = n // (C * D // gcd(C, D)) -    return n - x - y + z +def cnt(n): +    lcm = c // gcd(c, d) * d +    return n - n // c - n // d + n // lcm -print((f(B) - f(A - 1))) +print((cnt(b) - cnt(a - 1)))