a,b,c,d=list(map(int,input().split()))

from fractions import *

f=lambda x:x-x//c-x//d+x//(c*d//gcd(c,d))

print((f(b)-f(a-1)))
a,b,c,d=list(map(int,input().split()))

from math import *

f=lambda x:x-x//c-x//d+x//(c*d//gcd(c,d))

print((f(b)-f(a-1)))
a, b, c, d = list(map(int, input().split()))
from fractions import *

f = lambda x: x - x // c - x // d + x // (c * d // gcd(c, d))
print((f(b) - f(a - 1)))

a, b, c, d = list(map(int, input().split()))
from math import *

f = lambda x: x - x // c - x // d + x // (c * d // gcd(c, d))
print((f(b) - f(a - 1)))

-from fractions import * +from math import *