from fractions import gcd



def get_num(div):

  num = (B)//div - (A-1)//div

  return num



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

print((B-A+1-get_num(C)-get_num(D)+get_num(C*D//gcd(C,D))))
from fractions import gcd

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

total = B - A + 1

divC = B//C - (A-1)//C

divD = B//D - (A-1)//D

lcm = int(C * D / gcd(C, D))

divCD = B//lcm - (A-1)//lcm

print((total - divC - divD + divCD))

from fractions import gcd


def get_num(div):
    num = (B) // div - (A - 1) // div
    return num


A, B, C, D = list(map(int, input().split()))
print((B - A + 1 - get_num(C) - get_num(D) + get_num(C * D // gcd(C, D))))

from fractions import gcd

A, B, C, D = list(map(int, input().split()))
total = B - A + 1
divC = B // C - (A - 1) // C
divD = B // D - (A - 1) // D
lcm = int(C * D / gcd(C, D))
divCD = B // lcm - (A - 1) // lcm
print((total - divC - divD + divCD))

- -def get_num(div): -    num = (B) // div - (A - 1) // div -    return num - - -print((B - A + 1 - get_num(C) - get_num(D) + get_num(C * D // gcd(C, D)))) +total = B - A + 1 +divC = B // C - (A - 1) // C +divD = B // D - (A - 1) // D +lcm = int(C * D / gcd(C, D)) +divCD = B // lcm - (A - 1) // lcm +print((total - divC - divD + divCD))