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

import fractions

g = fractions.gcd(C, D)

ac = (A-1)//C

bc = B//C

c = bc-ac

ad = (A-1)//D

bd = B//D

d = bd-ad

cdg = (C*D)//g

acd = (A-1)//cdg

bcd = B//cdg

cd = bcd-acd

ans = B-A+1-c-d+cd

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

A -= 1

import math

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

a = A//C + A//D - A//g

b = B//C + B//D - B//g

ans = B - A - b + a

print(ans)
A, B, C, D = list(map(int, input().split()))
import fractions

g = fractions.gcd(C, D)
ac = (A - 1) // C
bc = B // C
c = bc - ac
ad = (A - 1) // D
bd = B // D
d = bd - ad
cdg = (C * D) // g
acd = (A - 1) // cdg
bcd = B // cdg
cd = bcd - acd
ans = B - A + 1 - c - d + cd
print(ans)

A, B, C, D = list(map(int, input().split()))
A -= 1
import math

g = C * D // math.gcd(C, D)
a = A // C + A // D - A // g
b = B // C + B // D - B // g
ans = B - A - b + a
print(ans)

-import fractions +A -= 1 +import math -g = fractions.gcd(C, D) -ac = (A - 1) // C -bc = B // C -c = bc - ac -ad = (A - 1) // D -bd = B // D -d = bd - ad -cdg = (C * D) // g -acd = (A - 1) // cdg -bcd = B // cdg -cd = bcd - acd -ans = B - A + 1 - c - d + cd +g = C * D // math.gcd(C, D) +a = A // C + A // D - A // g +b = B // C + B // D - B // g +ans = B - A - b + a