peterverebics/CodeNet_Python_118 huggingface dataset:
import math
import fractions
EPS = 1e-14

def ceil(x):
    return math.ceil(x - EPS)
def floor(x):
    return math.floor(x + EPS)

def countX(X) :
    if X > B :
        return 0
    minX = ceil(A / X)
    maxX = floor(B / X)

    return maxX - minX + 1

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

ans = B - A + 1

# 最小公倍数
Z = C * D // fractions.gcd(C,D)

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))
a,b,c,d=map(int,input().split())
dcou=b//d-(a-1)//d
ccou=b//c-(a-1)//c
from math import gcd
dc=d*c/gcd(d,c)
dccou=b//dc-(a-1)//dc
ans=b-a-dcou-ccou+dccou+1
print(int(ans))
def cnt(A, B, X):
    A1 = -(-A // X)
    B1 = B // X
    return B1 - A1 + 1

A, B, C, D = map(int,input().split())
print((B - A + 1) - cnt(A, B, C) - cnt(A, B, D) - cnt(A, B, C * D))
import math
l = list(map(int,input().split()))

l[0] -= 1
la = l[0] - l[0] // l[2] - l[0] // l[3] + l[0] // (l[2] * l[3])
lb = l[1] - l[1] // l[2] - l[1] // l[3] + l[1] // (l[2] * l[3])
print(lb - la)
a,b,c,d = map(int, input().split())
import fractions
r = b-a
g = c * d // fractions.gcd(c, d)

print(r - r//c - r//d + r//g)
def main2():
    a, b, c, d = list(map(int, input().split()))

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    if d % c == 0:
        di = c
    elif c % d == 0:
        di = d
    else:
        di = c*d
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()
from fractions import gcd

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

lcm = int((c*d) / gcd(c, d))
X = b - int(b/c) - int(b/d) + int(b/lcm)
Y = (a-1) - int((a-1)/c) - int((a-1)/d) + int((a-1)/lcm)
print(X-Y)
import math


# def calc(n, c, d):
#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n // c +
              n // d - n // (c * d / math.gcd(c, d)))

def main():
    a, b, c, d = map(int, input().split())

    print(calc(b, c, d)-calc(a-1, c, d))


if __name__ == "__main__":
    main()
a,b,c,d = map(int, input().split())
ans = b - a
cntc = b//c - (a-1)//c
cntd = b//d - (a-1)//d
cntcd = b//(c*d) - (a-1)//(c*d)
ans = ans - cntc - cntd + cntcd
print(ans)
import math
A,B,C,D = map(int,input().split())
count = 0
x = math.ceil((B/C)-(A/C))
y = math.ceil((B/D)-(A/D))
z = math.ceil((B/(C*D))-(A/(C*D)))

if A%C == 0 and B%C == 0:
  x += 1
if A%D == 0 and B%D == 0:
  y += 1
if A%(C*D) ==0 and B%(C*D) == 0:
  z += 1

ans = B-A+1 -(x+y-z)
print(ans)
import fractions as fc
import math
a,b,c,d=map(int,input().split())
ccnt=(b//c)-math.ceil(a//c)
dcnt=(b//d)-math.ceil(a//d)
e=int(c*d/fc.gcd(c,d))
ecnt=(b//e)-math.ceil(a//e)
ans=(b-a+1)-(ccnt+dcnt-ecnt)
print(ans)
import math
a,b,c,d = map(int, input().split())
e = c*d/(math.gcd(c,d))

ac = math.floor((a-1)/c)
bc = math.floor(b/c)
acd = math.floor((a-1)/e)
ad = math.floor((a-1)/d)
bd = math.floor(b/d)
bcd = math.floor(b/e)

xa = ac + ad - acd

xb = bc + bd - bcd

print(int(b-a+1-(xb-xa)))
a, b, c, d = map(int, input().split())
nbc = b // c
nac = (a - 1) // c
nc = nbc - nac
nbd = b // d
nad = (a - 1) // d
nd = nbd - nad
x, y = c, d
if x < y:
  x, y = y, x
  while x % y != 0:
    x, y = y, x % y
cd = (c * d) // y
nbcd = b // cd
nacd = a // cd
ncd = nbcd - nacd
t = nc + nd - ncd
at = b - a + 1 - t
print(at)
import fractions

A,B,C,D = map(int,input().split())
A -= 1
g = fractions.gcd(C, D)
l = C * D / g

sA = A // C
eA = A // D
lA = A - (eA + sA) + A // l

sB = B // C
eB = B // D
lB = B - (eB + sB) + B // l
print(int(lB - lA))
# Euclidean Algorithm (non-recursive)
def gcd2(m, n):
    while n:
        m, n = n, m % n
    return m

# lcm (least common multiple)
def lcm(m, n):
    return m//gcd2(m, n)*n

a, b, c, d = map(int, input().split())
ndiv = (b-a)//c + (b-a)//d - (b-a)//lcm(c,d)
print(b - a - ndiv )
def gcd(n,m):
    if(n%m==0): return m
    else: return gcd(m,n%m)
a,b,c,d = map(int,input().split())
x = b-b//c-b//d+b//(c*d//gcd(c,d))
y = a-a//c-a//d+a//(c*d//gcd(c,d))
print(x-y)
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

ans=0
ans+=b//c-(a-1)//c
ans+=b//d-(a-1)//d
q=lcm(c,d)
ans+=b//q-(a-1)//q
print(ans)
a, b, c, d = map(int, input().split())

num = b-a
c_1 = (b-a)//c
d_1 = (b-a)//d
cd_1 = (b-a)//(c*d)

ans = num - (c_1 + d_1) + cd_1
print(ans)
from fractions import gcd

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

cd_gcd = gcd(c, d)
cd_lcm = c * d // cd_gcd

ans = (b - a + 1) - (b - a +1)//c - (b - a +1)//d + (b - a +1)//cd_lcm
print(ans)
from fractions import gcd

l, r, x, y = map(int, input().split())
lcm = x * y / gcd(x, y)

xn = r // x - (l - 1) // x
yn = r // y - (l - 1) // y
xyn = r // lcm - (l - 1) // lcm
print(r - l + 1 - xn - yn + xyn)
from fractions import gcd
A, B, C, D = map(int, input().split())
print(int(B-A+1-(((B//C)+(B//D)-(B//(C*D/gcd(C,D))))-((A//C)+(A//D)-(A//(C*D/gcd(C,D)))))))
import math
A,B,C,D=map(int,input().split())

c=(int((B-B%C)-(A-1+C-(A-1)%C))/C+0.5)+1
d=(int((B-B%D)-(A-1+D-(A-1)%D))/D+0.5)+1
lcm=C*D/math.gcd(C,D)
candd=((B-B%lcm)-(A-1+lcm-(A-1)%lcm))/lcm+1
print(int(B-A+1-c-d+candd))
import math
A,B,C,D = map(int, input().split())

a, b = C,D
if a < b:
    a, b = b, a
while a % b != 0:
    a, b = b, a % b
# print(b)

t = C*D/b

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)

print(B-A+1-m+n)
from math import ceil
a,b,c,d=map(int,input().split())
def gcd(x,y):
    while y%x!=0:
        a=x
        x=y%x
        y=a
    return x

def num(l,r,x):
    return r//x-ceil(l/x)+1

def lcm(x,y):
    return x*y//gcd(x,y)

ans=0
ans+=(b-a+1)-(num(a,b,c)+num(a,b,d)-num(a,b,lcm(min(c,d),max(c,d))))
print(ans)
import math,fractions
A,B,C,D=map(float,input().split())
E=C*D//fractions.gcd(C,D)

ac=A//C
ad=A//D
bc=B//C
bd=B//D
ae=A//E
be=B//E

s=bc-ac
t=bd-ad
u=be-ae

print(s,t,u)
print(int(B-A+1 -(s+t) +u))
import fractions

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

def lcm(x,y):
    return x * y // fractions.gcd(x,y)

lcm_n = lcm(c,d)

ans = (b - a) - ((b-a)//c + (b-a)//d - (b // lcm_n) - (a // lcm_n))
print(ans)
import fractions

a,b,c,d=map(int,input().split())
C=int(b//c)-int((a-1)//c)
D=int(b//d)-int((a-1)//d)
g=fractions.gcd(c,d)
l=(c*d)/g
E=int(b//l)-int((a-1)//l)
print(int(b-a+1-C-D+E))
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C * D / fractions.gcd(C, D))

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()
import math
a,b,c,d = map(int,input().split())

dC = math.floor(b/c)-math.floor((a-1)/c)
dD = math.floor(b/d) - math.floor((a-1)/d)
lcm = c*d // math.gcd(c,d)
dCD = math.floor(b/lcm) - math.floor((a-1)/lcm) 
print(b - a + 1 -(dC + dD - dCD))
import fractions

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

f=fractions.gcd(c,d)
f2=c*d//f

p = b//c - (a-1)//c
q = b//d - (a-1)//d
r = b//(f2) - (a-1)//(f2)
a, b, c, d = map(int, input().split())
nbc = b // c
nac = (a - 1) // c
nc = nbc - nac
nbd = b // d
nad = (a - 1) // d
nd = nbd - nad
x, y = c, d
if x < y:
  x, y = y, x
  while x % y != 0:
    x, y = y, x % y
cd = (c * d) // y
nbcd = b // cd
nacd = (a - 1) // cd
ncd = nbcd - nacd
t = nc + nd - ncd
at = b - a + 1 - t
print(at)
import math
A, B, C, D = map(int, input().split())
c = B // C - A // C
d = B // D - A // D
E = int((C * D) / math.gcd(C, D))
e = B // E - A // E
print(B - A + 1 - c - d + e)
from fractions import gcd
a,b,c,d = map(int, input().split())
def f(p):
  if a % p ==0:
    return(b//p - a//p + 1)
  else:
    return(b//p - a//p)
  
print(b-a+1 - (f(c)+f(d) - f(c*d/gcd(c,d))))
import fractions
a,b,c,d=map(int,input().split())
gcd=fractions.gcd(c,d)
lcm=(c//gcd)*d

def num(a,x):
  return (a-(a%x))//x

n=(b-a+1)-(num(b,c)-num(a-1,c))-(num(b,d)-num(a-1,c))+(num(b,lcm)-num(a-1,lcm))
print(n)
import math

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


C_multiple = B // C - A // C
D_multiple = B // D - A // D 

if A % C == 0:
    C_multiple += 1
if A % D == 0:
    D_multiple += 1
        

CD_gcd = math.gcd(C,D)
CD_multiple = B // CD_gcd - A// CD_gcd 
if A % CD_gcd == 0:
    CD_multiple += 1

ans = ( B - A + 1 ) - (C_multiple + D_multiple - CD_multiple)

print(ans)
import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (math.floor((b)/c)-math.floor((a-1)/c))+(math.floor((b)/d)-math.floor((a-1)/d))- (math.floor((b)/(lc))-math.floor((a-1)/(lc)))
	print((b-(a-1))-cnt)
	

main()
import fractions
a,b,c,d = map(int, input().split())

def lcm(a,b):
    return a * b / fractions.gcd(a, b)

def count(num, a, b):
    return num - num//a - num//b + num//lcm(a,b)

print(int(count(b,c,d)-count(a-1,c,d)))
A,B,C,D = map(int,input().split())
ans = 0
for i in range(A,B+1):
    if i % (C*D)==0:
        print(ans)
        exit()
    else:
        ans+=1
import math
a,b,c,d = map(int,input().split())
e = c*d/math.gcd(c,d)
print(b-a+1 + ((b//e)-((a//e))+(a%e==0))-((b//c)-((a//c))+(a%c==0))-((b//d)-((a//d))+(a%c==0)))
A,B,C,D = map(int,input().split())

import fractions

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

ans = B - A -  (B//C - A//C + B//D - A//D -(B//X + A//X)) + 1

print(ans)
import math
a,b,c,d = map(int,input().split())

ans = b-(a-1)

def lcm(x,y):
    return x * y // math.gcd(x,y)

ca = math.floor((a-1)/c)
cb = math.floor(b/c)
da = math.floor((a-1)/d)
db = math.floor(b/d)
cda = math.floor((a-1)/lcm(c,d))
cdb = math.floor(b/lcm(c,d))
ans -= (cb+db-cdb) - (ca+da-cda)
print(ans)
A,B,C,D=map(int,input().split())

def unko(x,C,D):
  import fractions
  t=int(fractions.gcd(C,D))
  t_=C*D/t
  return x-(x//C+x//D-x//t_)
print(unko(B,C,D)-unko(A-1,C,D))
import math


def main():
    a, b, c, d = map(int, input().split())

    if b < c and b < d:
        print(b - a)
    else:
        print(b-a-(math.floor((b - a) / c) +
                   math.floor((b - a) / d) - math.floor((b - a) / (c*d/math.gcd(c, d)))))


if __name__ == "__main__":
    main()
import math
import fractions
a,b,c,d = map(int,input().split())
c_d = ((c*d)/(fractions.gcd(c,d)))
#print(c_d,c*d)
a_c = (a-1) // c
a_d = (a-1) // d
a_c_d = (a-1) // c_d
a_ans = (a-1) - a_c - a_d + a_c_d
#ans1 = (a_c + a_d - a_c_d)
#print(ans1)
b_c = b // c
b_d = b // d
b_c_d = b // c_d
b_ans = b - b_c - b_d + b_c_d
#ans2 = (b_c + b_d -b_c_d)
#print(ans2)
#print(math.floor((b-a+1)-(ans2-ans1)))
print(b_ans-a_ans)
import fractions
A,B,C,D = list(map(int,input().split()))
A -= 1
lcn = C * D / fractions.gcd(C,D) 
m_n = B - B // C - B // D + B // lcn
min_n = A - A // C - A // D + A // lcn
print(m_n-min_n)
A, B, C, D = map(int, input().split())
length = B + 1 - A
ans = length
CD = C * D
if A % C == 0:
    add_c = 0
else:
    add_c = C - A % C
ans -= (length - add_c) // C

if A % D == 0:
    add_d = 0
else:
    add_d = D - A % D
ans -= (length - add_d) // D

if A % CD == 0:
    add_cd = 0
else:
    add_cd = CD - A % CD
ans += (length - add_cd) // CD
print(ans)
import fractions
def lcm(A, B):
    return int((A * B) / fractions.gcd(A, B))
A, B, C, D = map(int, input().split())
length = B - A
cc = length // C
dd = length // D
ll = length // lcm(C, D)
print(length - cc - dd + ll)
import math
import fractions
A, B, C, D = map(int, input().split())


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,math.floor((x/y)))
    return math.floor((x/y))

# print(func(100,10))


lcm = int(C * D / fractions.gcd(C, D))
print( (B - (func(B, C) + func(B, D) - func(B, lcm))) -
       (A-1 - (func(A-1, C) + func(A-1, D) - func(A-1, lcm))) )
import math
A,B,C,D = map(int,input().split())

print(B-B//C-B//D+B//(C*D//math.gcd(C,D))-(A-A//C-A//D+A//(C*D//math.gcd(C,D)))+1)
import math
a,b,c,d = map(int,input().split())
h = a-b+1
e = c*d//math.gcd(c,d)
print(h-h//c-h//d+h//e)
import math
a,b,c,d = map(int,input().split())
h = a-b
e = c*d//math.gcd(c,d)
print(h-h//c-h//d+h//e)
import fractions
a,b,c,d = map(int,input().split())
l = (c*d)//fractions.gcd(c,d)
if fractions.gcd(c,d) == 1:
	l = 10**18+1
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))
	print(b-a-(num2-num)+1)
else:
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))-1
	print(b-a-(num2-num))
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())
ac = a // c if a % c != 0 else a // c - 1
bc = b // c
ad = a // d if a % d != 0 else a // d - 1
bd = b // d
a_cd_dup = a // (lcm(c, d))
b_cd_dup = b // (lcm(c, d))
divisible_count = (bc - ac) + (bd - ad) - (b_cd_dup - a_cd_dup)
ans = (b - a + 1) - divisible_count
print(ans)
from fractions import gcd
a,b,c,d = map(int,input().split())

lcm = c*d / gcd(c,d)

cdiv = b//c - (a-1)//c
ddiv = b//d - (a-1)//d

div = b//lcm -(a-1)//lcm

print(b-a+1 - cdiv - ddiv + div)
A,B,C,D=map(int,input().split())

def unko(x,C,D):
  import fractions
  t=fractions.gcd(C,D)
  t_=C*D/t
  return x-(x//C+x//D-x//t_)
print(int(unko(B,C,D)-unko(A-1,C,D)))
import math

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

lcm = c*d // math.gcd(c, d)

dif = b-a
div_c = dif//c
div_d = dif//d
div_cd = dif//(lcm)

ans = dif - (div_c + div_d) + div_cd
print(int(ans))
A,B,C,D = map(int,input().split())
count = 0
for i in range(A,B+1):
  if i%C != 0 and i%D != 0:
    count += 1
  else:
    break
print(count)
A, B, C, D = map(int,input().split())

cnt = 0

for i in range(A, B+1):
  if i % (C*D) == 0:
    cnt += 1

print(cnt)
import math
A,B,C,D = map(int, input().split())
ans1 = B//C+B//D
g = math.gcd(C, D)
l = C*D/g
ans1 -= B//l
ans2 = (A-1)//C+(A-1)//D
ans2 -= (A-1)//l
ans = B-ans1-A+ans2+1
print(int(ans))
import fractions

A,B,C,D = list(map(int, input().split()))
cc = int(B/C) - int((A-1)/C)
dd = int(B/D) - int((A-1)/D)
cd = int(C*D / fractions.gcd(C,D))
ee = int(B/(cd)) - int((A-1)/(cd))
U = B-A+1
print(U - (cc + dd - ee))
from fractions import gcd

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

cnt = 0
lcm = c * d / gcd(c, d)
a -= 1

under_b = b - (b//c + b//d) + b//lcm
under_a = a - (a//c + a//c) + a//lcm
answer = under_b - under_a

print(answer)
def main():
    #n = int(input())
    a,b,c,d = map( int, input().split())

    c_baisuu = int(b/c)-int((a-1)/c)
    d_baisuu = int(b/d)-int((a-1)/d)
    cd_baisuu = int(b/(c*d))-int((a-1)/(c*d))
    zenbu = b-a+1
    print(zenbu-(c_baisuu+d_baisuu-cd_baisuu))
    
if __name__ == '__main__':
    main()
a,b,c,d = map(int,input().split())
r = 0
f = c*d
e = b-a
r += int(e/c)
r += int(e/d)
r -= int(e/f)
if(e%c == 0):
    r -= 1
if(e%d == 0):
    r -= 1
print(e-r)
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

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

c_div=math.floor(b/c)-math.floor((a-1)/c)
d_div=math.floor(b/d)-math.floor((a-1)/d)
cd_div=math.floor(b/lcm(c,d))-math.floor((a-1)/lcm(c,d))

ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)
def main():
    import fractions 
    import math
    a,b,c,d = map(int,input().split())
    m = c*d//fractions.gcd(c,d)
    c_=math.ceil(a/c)*c
    d_=math.ceil(a/d)*d
    c__ = math.floor(b/c)*c
    d__ = math.floor(b/d)*d
    m_ = math.ceil(a/m)*m
    m__ = math.floor(b/m)*m
    print(b-a-((c__-c_)//c+(d__-d_)//d-(m__-m_)//m))

if __name__ == "__main__":
    main()
import numpy as np
import fractions

gcd = fractions.gcd

def main():
    #n = int(input())
    a,b,c,d = map( int, input().split())

    c_baisuu = int(b/c)-int((a-1)/c)
    d_baisuu = int(b/d)-int((a-1)/d)
    cd = c * d / gcd(c, d)
    cd_baisuu = int(b/(cd))-int((a-1)/(cd))
    zenbu = b-a+1
    print(zenbu-(c_baisuu+d_baisuu-cd_baisuu))
    
if __name__ == '__main__':
    main()
import fractions
A,B,C,D=map(int, input().split())

AmimanCD = (A-1)//C + (A-1)//D - (A-1)//(C*D/fractions.gcd(C,D))
BikaCD   =  B   //C +  B   //D -  B   //(C*D/fractions.gcd(C,D))
AB_CD = round(BikaCD-AmimanCD)
print(B-A+1-AB_CD)
import fractions
a,b,c,d = map(int,input().split())
#N(C cup d) = N(C)+N(D) - N(C cap D)
# N(C)
X = b//c
Y = a//c
C =(X-Y)
# N(D)
x = b//d
y = a//d
D =(x-y)
# N(C cap D)
def lcm(x,y):
  return (x*y) // fractions.gcd(x,y)
koubaisu = lcm(c,d)
alpha = b//koubaisu
bata = a//koubaisu
E = alpha - bata
ans_1 = C+D-E
ans_2 = (b-a+1)-ans_1
print(ans_2)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

a, b, c, d = map(int, readline().split())
print((b - a + 1) - (b // c + b // d) + ((a - 1) // c + (a - 1) // d) + b // (c * d // gcd(c, d)) - a // (c * d // gcd(c, d)))
a,b,c,d=map(int,input().split())
print(b-a+1-(b//c+b//d-b//(c*d)-a//c-a//d+a//(c*d)))
a, b, c, d = map(int, input().split())


x = ((b+1) // c) - ((a+1) // c)
y = ((b+1) // d) - ((a+1) // d)


import fractions
e = int(c * d / fractions.gcd(c,d))


z = ((b+1) // e) - ((a+1) // e)


print((b-a) - (x+y-z) + 1)
li = list(map(int,input().split()))
countC = li[1] // li[2] - (li[0]-1) // li[2]

countD = li[1] // li[3] - (li[0]-1) // li[3]

countCD = li[1] // (li[2] * li[3]) - (li[0]-1) // (li[2] * li[3])

re = (li[1] - li[0] + 1) - (countC +countD - countCD)

# print(countC)
# print(countD)
# print(countCD)
print(re)
A, B, C, D = map(int, input().split())
r = B - A
print(r - r // C - r // D + r // (C * D))
import fractions
from math import floor
a,b,c,d=map(int,input().split())
mod=c*d//fractions.gcd(c,d)
print(b-a+1-floor(b/c)+floor((a-1)/c)-floor(b/d)+floor((a-1)/d)+floor(b/mod)-floor((a-1)/mod))
import math

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

s1=b//c - math.ceil(a/c) + 1
s2=b//d - math.ceil(a/d) + 1
s12=b//(c*d) - math.ceil(a/(c*d)) + 1

print(b-a+1-(s1+s2-s12))
import fractions
#import math

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

# cで割り切れる、またはdで割り切れるものから、両方で割り切れるものを引く

# cで割り切れる; i
i = b//c - a//c

# dで割り切れる; j
j = b//d - a//d

#両方で割り切れる; k
lcm = a*b / (fractions.gcd(a,b))
#lcm = a*b / (math.gcd(a,b))
k = b//lcm - a//lcm

print(int((b-a+1)-i-j+k))
a,b,c,d=map(int,input().split())
q=[a,b]
for w in range(0,2):
    x=q[w]//c
    y=q[w]//d
    k,j=c,d
    g=c%d
    while g!=0:
        k,j=d,g
        g=k%j
    l=c*d/j
    z=q[w]//l
    q[w]=q[w]-x-y+z
print(int(q[1]-q[0]+1))
a , b , c , d = map(int,input().split())

p = b//c - (a-1)//c
q = b//d - (a-1)//d
r = b//(c*d) - (a-1)//(c*d)


print((b-a+1) - (p+q-r))
import sys

def lcm(c, d):
    c, d = max(c, d), min(c, d)
    cd = c * d
    while c % d > 0:
        c, d = d, c % d
    return cd // d

def solve():
    A, B, C, D = map(int, input().split())
    cd = lcm(C, D)
    divC = (B + 1) // C - A // C
    divD = (B + 1) // D - A // D
    divCD = (B + 1) // cd - A // cd
    print((B - A + 1) - (divC + divD - divCD))

    return 0

if __name__ == "__main__":
    solve()
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C * D // fractions.gcd(C, D))

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()
from fractions import gcd

lcm = lambda x, y: x*y // gcd(x, y)

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

b_ = b
b_ -= b // c
b_ -= b // d
b_ += b // lcm(c, d)

a_ = a - 1
a_ -= a_ // c
a_ -= a_ // d
a_ += a_ // lcm(c, d)


print(b_ - a_)
import fractions

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

def lcm(x,y):
    return x * y // fractions.gcd(x,y)

lcm_n = lcm(c,d)

ans = (b - a-1) -((b-a-1)//c + (b-a-1)//d - (b-a-1) // lcm_n)
print(ans)
from math import *
a,b,c,d = map(int,input().split())
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= b//f
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0 or a%d ==0:
  div1+=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print(mm-roger)
import fractions
A, B, C, D = map(int, input().split())


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,int(x/y))
    # return int((x/y))
    # print(x,y,x//y)
    return int((x//y))

# print(func(100,10))


lcm = (C * D) / int(fractions.gcd(C, D))
print(int( B - func(B, C) - func(B, D) + func(B, lcm) - A + 1 + func(A-1, C) + func(A-1, D) - func(A-1, lcm)))
import math
a,b,c,d = map(int,input().split())

ans = b-a+1
#print(ans)

def lcm(x,y):
    return x * y // math.gcd(x,y)

#C:number of integers between a and b that can be divided by c 
C = math.floor(b/c) - math.ceil(a/c) + 1
D = math.floor(b/d) - math.ceil(a/d) + 1
CD = math.floor(b/lcm(c,d)) - math.ceil(a/lcm(c,d)) + 1
ans -= (C + D - CD)
#print(C,D,CD)
print(ans)
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = c*d/gcd(c,d)
    db = b - (b//c + b//d - b//e)    
    da = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//e)
    print(int(db-da))

      
resolve()
import fractions
A,B,C,D = map(int,input().split())
g = C * D // fractions.gcd(C,D)
# A以下
cntA = 0
cntA += A // C
cntA += A // D
cntA -= A // g

# B未満
cntB = 0
cntB += B // C
cntB += B // D
cntB -= B // g

cnt = cntA - cntB
cnt = (A - B + 1) - cnt

print(cnt)
import math
a,b,c,d=map(int,input().split())
ans=0
ans+=(b//c-a//c+(a%c==0))
ans+=(b//d-a//d+(a%d==0))
#lcm=c*d//math.gcd(c,d)
lcm=c*d
ans-=(b//lcm-a//lcm+(a%lcm==0))
print(b-a+1-ans)
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

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

g = math.gcd(c, d)
l = lcm(c, d)

print(b-a+1 - (b//c - a//c + b//d - a//d -b//l + a//l))
a,b,c,d=map(int, input().split())
tc = b//c-a//c
td = b//d-a//d
tcd = b//(c*d)-a//(c*d)
print(b-a+1-tc-td+tcd)
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = c*d/gcd(c,d)
    db = int(b - (int(b/c) + int(b/d) - int(b/e)))
    da = int((a-1) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e)))
    print(int(db-da))
resolve()
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    a,b,c,d = IL()
    length = b-a
    mc = length//c
    md = length//d
    lcm = (c*d)//math.gcd(c,d)
    mcd = length//lcm
    print(length-mc-md+mcd)
    exit()
import sys
import math

A,B,C,D = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


maru1 = B // C
maru2 = A // C

maru3 = B // D
maru4 = A // D

maru5 = B // lcm(C,D)
maru6 = A // lcm(C,D)

ans_tmp = ((maru1-maru2)+(maru3-maru4)) - (maru5-maru6)
ans = ((B-A)+1) - ans_tmp

print(ans)
from math import ceil, floor

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

divC = floor(b/c)-ceil(a/c)
divD = floor(b/d)-ceil(a/d)
res = (b-a) - (divC+divD)

print(res)
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)
a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(c, d)

cs = b//c - a//c + 1
ds = b//d - a//d + 1
cds = b//cd - a//cd + 1

print(all - cs - ds + cds)
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  A,B,C,D=map(int,pin().split())
  M=B//C+B//D-B//(C*D)
  m=(A-1)//C+(A-1)//D-(A-1)//(C*D)
  t=M-m 
  print(B-A+1-t)
  return 
main()
import fractions

a,b,c,d = map(int, input().split())
total = b-a+1
lcm = c*d / fractions.gcd(c,d)
x = (b//c) - ((a-1)//c)
y = (b//d) - ((a-1)//d)
z = (b//lcm) - ((a-1)//lcm)
#print(x,y,z)
print(int(total - (x + y - z)))