from fractions import gcd

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

ans = B - A + 1

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

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

x = C * D // gcd(C, D)

ans += (B // x - (A - 1) // x)

print(ans)
import math

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

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

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

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

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

ans = (B - A + 1) - (cdiv + ddiv - cddiv)

print(ans)
from fractions import gcd

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

import math

A, B, C, D = list(map(int, input().split()))
cdiv = B // C - (A - 1) // C
ddiv = B // D - (A - 1) // D
lcm = (C * D) // math.gcd(C, D)
cddiv = B // lcm - (A - 1) // lcm
ans = (B - A + 1) - (cdiv + ddiv - cddiv)
print(ans)

-from fractions import gcd +import math -ans = B - A + 1 -ans -= B // C - (A - 1) // C -ans -= B // D - (A - 1) // D -x = C * D // gcd(C, D) -ans += B // x - (A - 1) // x +cdiv = B // C - (A - 1) // C +ddiv = B // D - (A - 1) // D +lcm = (C * D) // math.gcd(C, D) +cddiv = B // lcm - (A - 1) // lcm +ans = (B - A + 1) - (cdiv + ddiv - cddiv)