from sys import stdin

import fractions

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

kouyaku = fractions.gcd(c, d)

koubai = c * d // fractions.gcd(c, d)

b_s = b - b//c - b//d + b//koubai

a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai

print((b_s - a_s))
from math import gcd



def lcm(x, y):

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



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



cd = lcm(c,d)

ab = b-a+1



print((ab-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//cd-(a-1)//cd)))
from sys import stdin
import fractions

a, b, c, d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = fractions.gcd(c, d)
koubai = c * d // fractions.gcd(c, d)
b_s = b - b // c - b // d + b // koubai
a_s = a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // koubai
print((b_s - a_s))

from math import gcd


def lcm(x, y):
    return (x * y) // gcd(x, y)


a, b, c, d = list(map(int, input().split()))
cd = lcm(c, d)
ab = b - a + 1
print(
    (ab - (b // c - (a - 1) // c) - (b // d - (a - 1) // d) + (b // cd - (a - 1) // cd))
)

-from sys import stdin -import fractions +from math import gcd -a, b, c, d = [int(x) for x in stdin.readline().rstrip().split()] -kouyaku = fractions.gcd(c, d) -koubai = c * d // fractions.gcd(c, d) -b_s = b - b // c - b // d + b // koubai -a_s = a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // koubai -print((b_s - a_s)) + +def lcm(x, y): +    return (x * y) // gcd(x, y) + + +a, b, c, d = list(map(int, input().split())) +cd = lcm(c, d) +ab = b - a + 1 +print( +    (ab - (b // c - (a - 1) // c) - (b // d - (a - 1) // d) + (b // cd - (a - 1) // cd)) +)