import sys

import fractions

import numpy as np



def hoge(A,B,g):

    min_r = A//g

    if A%g != 0:

        min_r += 1



    max_r = B//g



    return max_r - min_r + 1



if __name__ == '__main__' :

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

    

    num_c = hoge(A,B,C)

    num_d = hoge(A,B,D)

    E = (C*D)//fractions.gcd(C,D)

    num_e = hoge(A,B,E)



    print((1+B-A-(num_c + num_d - num_e)))

import math



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



cd = (C * D) // math.gcd(C, D)



pac, qac = divmod(A, C)

pad, qad = divmod(A, D)

pacd, qacd = divmod(A, cd)



pbc, qbc = divmod(B, C)

pbd, qbd = divmod(B, D)

pbcd, qbcd = divmod(B, cd)



pac = pac - 1 if qac == 0 else pac

pad = pad - 1 if qad != 0 else pad

pacd = pacd - 1 if qacd != 0 else pacd



ans = (pbc + pbd - pbcd) - (pac + pad - pacd)

print((B - A - ans + 1))



import sys
import fractions
import numpy as np


def hoge(A, B, g):
    min_r = A // g
    if A % g != 0:
        min_r += 1
    max_r = B // g
    return max_r - min_r + 1


if __name__ == "__main__":
    A, B, C, D = list(map(int, input().split()))
    num_c = hoge(A, B, C)
    num_d = hoge(A, B, D)
    E = (C * D) // fractions.gcd(C, D)
    num_e = hoge(A, B, E)
    print((1 + B - A - (num_c + num_d - num_e)))

import math

A, B, C, D = list(map(int, input().split()))
cd = (C * D) // math.gcd(C, D)
pac, qac = divmod(A, C)
pad, qad = divmod(A, D)
pacd, qacd = divmod(A, cd)
pbc, qbc = divmod(B, C)
pbd, qbd = divmod(B, D)
pbcd, qbcd = divmod(B, cd)
pac = pac - 1 if qac == 0 else pac
pad = pad - 1 if qad != 0 else pad
pacd = pacd - 1 if qacd != 0 else pacd
ans = (pbc + pbd - pbcd) - (pac + pad - pacd)
print((B - A - ans + 1))

-import sys -import fractions -import numpy as np +import math - -def hoge(A, B, g): -    min_r = A // g -    if A % g != 0: -        min_r += 1 -    max_r = B // g -    return max_r - min_r + 1 - - -if __name__ == "__main__": -    A, B, C, D = list(map(int, input().split())) -    num_c = hoge(A, B, C) -    num_d = hoge(A, B, D) -    E = (C * D) // fractions.gcd(C, D) -    num_e = hoge(A, B, E) -    print((1 + B - A - (num_c + num_d - num_e))) +A, B, C, D = list(map(int, input().split())) +cd = (C * D) // math.gcd(C, D) +pac, qac = divmod(A, C) +pad, qad = divmod(A, D) +pacd, qacd = divmod(A, cd) +pbc, qbc = divmod(B, C) +pbd, qbd = divmod(B, D) +pbcd, qbcd = divmod(B, cd) +pac = pac - 1 if qac == 0 else pac +pad = pad - 1 if qad != 0 else pad +pacd = pacd - 1 if qacd != 0 else pacd +ans = (pbc + pbd - pbcd) - (pac + pad - pacd) +print((B - A - ans + 1))