from fractions import gcd



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

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



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

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

c = B//E-(A-1)//E

print((B-A+1-a-b+c))
from math import gcd

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

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



c1 = (B//C)-((A+C-1)//C)+1

c2 = (B//D)-((A+D-1)//D)+1

c3 = (B//E)-((A+E-1)//E)+1

ans = B-A+1-c1-c2+c3



print(ans)

from fractions import gcd

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

from math import gcd

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

-from fractions import gcd +from math import gcd -E = (C * D) // gcd(C, D) -a = B // C - (A - 1) // C -b = B // D - (A - 1) // D -c = B // E - (A - 1) // E -print((B - A + 1 - a - b + c)) +E = C * D // gcd(C, D) +c1 = (B // C) - ((A + C - 1) // C) + 1 +c2 = (B // D) - ((A + D - 1) // D) + 1 +c3 = (B // E) - ((A + E - 1) // E) + 1 +ans = B - A + 1 - c1 - c2 + c3 +print(ans)