peterverebics/CodeNet_Python_118 huggingface dataset:
data = input().split()

a = int(data[0])
b = int(data[1])
c = int(data[2])
d = int(data[3])

multi = c * d

count = 0

for i in range(a, b + 1):
  if i % multi != 0:
    count += 1

print(count)
import math
a,b,c,d = map(int, input().split())
e = c*d/(math.gcd(c,d))

ac = math.floor(a/c)
bc = math.floor(b/c)
acd = math.floor(a/e)
ad = math.floor(a/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)))
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())

#nc=B//C-(A-1)//C
nc=int(B/C)-int((A-1)/C)
#nd=B//D-(A-1)//D
nd=int(B/D)-int((A-1)/D)
cd=int(C*D/gcd(C,D))
#ncd=B//cd-(A-1)//cd
ncd=int(B/cd)-int((A-1)/cd)
print(int(B-A+1-nc-nd+ncd))
import math

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

n=b-a+1

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

cc=math.ceil(n/c)
dc=math.ceil(n/d)
xc=math.ceil(n/x)

print(n-cc-dc+xc)
import math
a,b,c,d = map(int, input().split())
e = c*d/(math.gcd(c,d))

ac = math.ceil(a/c)
bc = math.floor(b/c)


ad = math.ceil(a/d)
bd = math.floor(b/d)

ae = math.ceil(a/e)
be = math.floor(b/e)

if b/c-a/c<1:
  xc = 0
else:
  xc = bc-ac + 1
if b/d-a/d<1:
  xd = 0
else:
  xd = bd-ad + 1
if b/e-a/e<1:
  xe = 0
else:
  xe = be-ae + 1
  
f = xc + xd - xe
g = b-a+1
h = g - f
print(h)
import math
a,b,c,d = map(int,input().split())
e = int(c*d/math.gcd(c,d))
wa = 0
c_seki = 0
d_seki = 0
e_seki = 0
c_seki = int(b/c)-int((a-1)/c)
d_seki = int(b/d)-int((a-1)/d)
e_seki = int(b/e)-int((a-1)/e)
wa = c_seki+d_seki-e_seki
print(b-a+1-wa)
A,B,C,D=map(int,input().split())
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

lcm_=lcm(C,D)
answer=B-A+1-(B//C-A//C)-(B//D-A//D)+(B//lcm_-A//lcm_)
if A%C==0:
    answer-=1
if A%D==0:
    answer-=1
if answer<=-1:
    print(0)
else:
    print(answer)
import math
import fractions
A,B,C,D= map(int,input().split())
c = math.floor(B/C)-math.ceil(A/C) + 1
d = math.floor(B/D)-math.ceil(A/D) + 1
s = C*D//fractions.gcd(C,D)
e = math.floor(B/s)-math.ceil(A/s) + 1
print(B-A+1-c-d+e)
import fractions
a,b,c,d = map(int,input().split())

ans = b - a + 1
cd = c*d/fractions.gcd(c,d)
tmp = int(b / c) - int((a-1) / c)
tmp2 = int(b / d) - int((a-1) / d)
tmp3 = int(b / cd) - int((a-1) / cd)
print(ans - tmp - tmp2 + tmp3 )
from fractions import gcd
a,b,c,d=map(int,input().split())
cnt1,cnt2=0,0
cnt1=(a-1)//c+(a-1)//d-((a-1)*gcd(c,d))//(c*d)
cnt2=b//c+b//d-(b*gcd(c,d))//(c*d)
print(cnt2-cnt1)
from fractions import gcd

a,b,c,d = map(int,input().split())
count = (b-(b//c+b//d-b//(c*d/gcd(c,d)))) - ((a-1)-((a-1)//c+(a-1)//d-(a-1)//(c*d/gcd(c,d))))
print(int(count))
import fractions
A,B,C,D = (int(x) for x in input().split())
c = 0
d = 0
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
M = lcm(C,D)
c = B//C - A//C
d = B//D - A//D
m = B//M - A//M
print(B-A+1-(c+d-m))
from fractions import gcd
import math
a,b,c,d = map(int,input().split())
dum = b-a
ans1 = dum//c
ans2 = dum//d
ans3 = dum//(c*d/gcd(c,d))

print(math.ceil(dum-ans1-ans2+ans3))
#print(ans1,ans2,ans3)
A, B, C, D = map(int, input().split())

def abc131_c(a,b,c,d):
    count = 0
    for i in range(a,b-1):
        if i % c == 0 or i % d == 0:
            continue
        count += 1
    return count
  
print(abc131_c(A,B,C,D))
import math

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

def lec(a, b):
    # aとbの最小公倍数
    return a * b // math.gcd(a, b)

CD = lec(C, D)
C_num = math.floor(B / C) - math.ceil(A / C) + 1
D_num = math.floor(B / D) - math.ceil(A / D) + 1
CD_num = math.floor(B / CD) - math.ceil(A / CD) + 1

answer = B - A + 1 - C_num - D_num + CD_num

print(answer)
import fractions
a,b,c,d = map(int,input().split())
e,f,g,h,i,j = b//c,b//d,(a-1)//c,(a-1)//d,b//((c*d)/fractions.gcd(c,d)),(a-1)//((c*d)/fractions.gcd(c,d))
print(int(b-(e+f-i)-(a-1-(g+h-j))))
A, B, C, D = map(int, input().split())
count = 0
for i in range(A,B):
    if i%C!=0 and i%D!=0:
        count += 1
print(count)
a, b ,c ,d = map(int, input().split())
print((b - a) - (b / c - a / c) + (b / d - a / d) - (b / (c * d) - a / (c * d)))
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 / fractions.gcd(C, D) * 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()
from math import ceil
from fractions import gcd


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

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

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

cn=num(a,b,c)
dn=num(a,b,d)
cdn=num(a,b,lcm(min(c,d),max(c,d)))

ans=(b-a+1)-(cn+dn-cdn)
print(ans)
import math

def gcd(p, q):
  if(q==0):
    return p
  else:
    return gcd(q, p%q)

def lcm(p, q):
  m=p/gcd(p,q)
  n=q/gcd(p,q)
  return gcd(p,q)*m*n

def num_div(N, C, D):
  nC=math.floor(N/C)
  nD=math.floor(N/D)
  nCD=math.floor(N/lcm(C,D))
  return nC+nD-nCD

A, B, C, D=map(int, input().split())
M=num_div(B, C, D)-num_div(A-1, C, D)
ans=B-A+1-M
print(ans)
import math

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

a = int(B / C) - int((A-1) / C)
b = int(B / D) - int((A-1) / D) 
c = C * D 
d = int(B / c) - int((A-1) / c)

Ans = (B - A + 1) - a - b + d 
print(Ans)
import math
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1

n_c=math.floor(b/c)-math.ceil(a/c)+1
n_d=math.floor(b/d)-math.ceil(a/d)+1
cd=c*d/fractions.gcd(c,d)
n_cd=math.floor(b/cd)-math.ceil(a/cd)+1
print(base-n_c-n_d+n_cd)
import math

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

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

x = b//c-a//c 

x += b//d-a//d

x -= b//e-a//e 

if a%c == 0:
    x += 1
    
if a%d == 0:
    x += 1
    
if a%e == 0:
    x += 1
    
print(b-a-x+1)
a,b,c,d = map(int,input().split())

bc = b//c
bd = b//d

import math
bcd = c*d/math.gcd(c,d)

ac = (a-1)//c
ad = (a-1)//d
acd = (a-1)//math.gcd(c,d)

ans = (b-(bc-bd+bcd))-(a-1-(ac-ad+acd))

print(int(ans))
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 calc2(n, m):
    return n-(math.floor(n / m))


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

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


if __name__ == "__main__":
    main()
import fractions
a,b,c,d = map(int,input().split())
num = b-a+1
ac = int((a-1)/c)
ad = int((a-1)/d)
bc = int(b/c)
bd = int(b/d)
e = c*d//(fractions.gcd(c,d))
a = int(a/e)
b = int(b/e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))
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)-int(a)+1-int(D)-int(C)+int(E))
import math
A, B, C, D = map(int, input().split())
cnt = 0
LCD = C*D/math.gcd(C,D)

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

print(int(ans))
import math

x = input().split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)
print(c_count)
print(d_count)
import fractions
import math

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

NUM = B-A+1 #対象にしてる整数の個数
CD = int((C*D)/fractions.gcd(C,D))

if A%C == 0:
  DivC = math.ceil(NUM/C)
else:
  NUMC = NUM-(C-A%C)
  DivC = math.ceil(NUMC/C)

if A%D == 0:
  DivD = math.ceil(NUM/D)
else:
  NUMD = NUM-(D-A%D)
  DivD = math.ceil(NUMD/D)

if A%CD == 0:
  DivCD = math.ceil(NUM/CD)
else:
  NUMCD = NUM-(CD-A%CD)
  DivCD = math.ceil(NUMCD/CD)


print(NUM - DivC -DivD + DivCD)
import sys

inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c, d = inintm()

print(b-a+1 - (-(-(b-a)//c) + -(-(b-a)//d)) + 1)
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)
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 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)
if ans<0:
	ans=0
print(ans)
import math
A,B,C,D = map(int, input().split())

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / (C*D))
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / (C*D))
 
print(B-A+1-(m-n))
import fractions
a, b, c, d = map(int, input().split())
print((b-a+1)-(((b//c)+(b//d))-(((a-1)//c)+((a-1)//d))-(b//(c*d//fractions.gcd(c,d)))))
import math
a,b,c,d=map(int,input().split())
lcm=(c*d)//math.gcd(c,d)
ans=(b-a)-((b//c-a//c)+(b//d-a//d)-(b//lcm-a//lcm))+1
print(ans)
import math
a,b,c,d=map(int,input().split())
lcm=c*d/math.gcd(c,d)
a1,a2,a3=int((a-1)/c),int((a-1)/d),int((a-1)/lcm)
b1,b2,b3=int(b/c),int(b/d),int(b/lcm)
ans=int(b-a+1-(b1+b2-b3-a1-a2+a3))
print(ans)
from fractions import gcd
a,b,c,d = map(int, input().split())
x = (c*d) // gcd(c,d)
c1, d1, cd1 = b // c, b // d, b // x
c2, d2, cd2 = (a-1) // c, (a-1) // d, a // x
ans = (c1+d1-cd1) - (c2+d2-cd2)
print(b-a+1-ans)
import math
a,b,c,d = map(int,input().split())

a -= 1
a_b = c * d // math.gcd(c, d)
print(a_b)
ans_a = a - (a // c + a // d - a // a_b)
ans_b = b - (b // c + b // d - b // a_b)

print(int(ans_b-ans_a))
import fractions

A, B, C, D = [int(i) for i in input().split()]

l = (C * D) // fractions.gcd(C,D)
b_sum = B -(B//C) - (B//D) + (B//l)
a_sum = A - (A//C) - (A//D) + (A//l)

print(b_sum - a_sum)
import math

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


lcm = a * b / math.gcd(a, b)

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

ans = num - (c_1 + d_1) + cd_1
print(ans)
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)


def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-math.floor(n/d)-math.floor(n/c)+math.floor(n/koubai)
print(warikiri(b,c,d)-warikiri(a-1,c,d))
import math
A,B,C,D=map(int,input().split())
E=C*D/math.gcd(C,D)
c=B//C-(A-1)//C
d=B//D-(A-1)//D
e=B//E-(A-1)//E
print(int(B-A+1-c-d+e))
from fractions import gcd
from math import ceil
a,b,c,d = map(int, input().split())

nums = b-a+1
t1 = ceil(b/c - a/c)
t2 = ceil(b/d - a/d)

lcm = (c*d)//gcd(c,d)
t3 = b//lcm - a//lcm
print(nums-t1-t2+t3)
import math

A, B, C, D = map(int, input().split())
CD = int(C * D // math.gcd(C, D))

B_in_C = int(B/C)
B_in_D = int(B/D)
B_in_CD = int(B/(CD))
B_con = B - (B_in_C + B_in_D - B_in_CD)

A = A-1 if A > 1 else A
A_in_C = int(A/C)
A_in_D = int(A/D)
A_in_CD = int(A/(CD))
A_con = A - (A_in_C + A_in_D - A_in_CD)

print(B_con - A_con)
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1
lcm = int(C / gcd(C, D) * D)
nA = A - (int(A/C) + int(A/D) - int(A/lcm))  
nB = B - (int(B/C) + int(B/D) - int(B/lcm))
print(nB - nA)
def getDivCount( a, b, x ):
    count=0
    if a==0 :
        count+=1

    if a<=x :
        ai = x
    else:
        ai = (a//x)*x
        if ai<a :
            ai +=x
    if ai<=b :
        count+=1
        count+=(b-ai)//x
    return count

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

count = b-a+1
count -= getDivCount(a,b,c)
if c!=d :
    count -= getDivCount(a,b,d)
    count += getDivCount(a,b,c*d)
print(count)
from fractions import gcd
A,B,C,D = map(int,input().split())
N=B-A+1
CD = (C * D) // gcd(C,D)
print(N - (N//C) - (N//D) + (N//CD) )
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(int(calc(b, c, d)-calc(a-1, c, d)))


if __name__ == "__main__":
    main()
A,B,C,D = map(int,input().split())

import math

numC = 0
numD_C = 0

cA = math.ceil(A/C)
cB = math.ceil(B/C)
dA = math.ceil(A/D)
dB = math.ceil(B/D)

i = 1
num = 0

while A <= C*D*i <=B:
    num += 1
    i += 1

ans = B-A +1-(abs(cB-cA) + abs(dB-dA) - num)

print(ans)
import fractions

a,b,c,d = map(int, input().split(" "))
gcd = fractions.gcd(c, d)
lcm = c * d / gcd
bwari = b - ((int)(b/c) + (int)(b/d) - (int)(b/(lcm)))
awari = (a - 1)- ((int)((a-1)/c) + (int)((a-1)/d) - (int)((a-1)/(lcm)))
print(bwari - awari)
a,b,c,d=map(int,input().split())
x=(b-a+1)//c
y=(b-a+1)//d
z=(b-a+1)//(c+d)
print(b-a-1-x-y+z)
from fractions import gcd


def lcm(c, d):
    return (c * d) // gcd(c, d)


def main():
    a, b, c, d = map(int, input().split())
    c_num = (b//c-(a-1)//c)
    d_num = (b//d-(a-1)//d)
    cd_num = (b//lcm(c, d)-a//lcm(c, d))
    ans = b-a+1-c_num-d_num+cd_num
    print(ans)


if __name__ == "__main__":
    main()
from fractions import gcd
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//gcd(C, D) - (A-1)//gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)
import math
a,b,c,d=map(int,input().split())
lcm_cd=c*d/math.gcd(c,d)
c_times=b//c-(a-1)//c
d_times=b//d-(a-1)//d
cd_times=b//lcm_cd-(a-1)//lcm_cd
print(int(b-a+1-c_times-d_times+cd_times))
A, B, C, D = map(int, input().split())

E = max(C, D)
while True:
    if E % min(C, D) == 0:
        break
    E += max(C, D)

print(B - A - (B-A)//C - (B-A)//D + (B-A)//E)
import math
import fractions
EPS = 1e-12

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())
cd = c * d
n_c = 0
n_d = 0
n_cd = 0
i = ( a / c + 1 ) * c
while i <= b:
    n_c += 1
    i *= c
i = ( a / d + 1 ) * d
while i <= b:
    n_d += 1
    i *= c
i = ( a / cd + 1 ) * cd
while i<= b:
    n_cd += 1
    i*=cd
print(b-a+1+n_c+n_d-n_cd)
import math
A,B,C,D = map(int,input().split())

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

i = B//C
j = B//D
k = A//C
n = A//D
m = B//E
l = A//E

res = B-(A-1)-(i-k)-(j-n)+(m-l)
print(math.floor(res))
import fractions
A,B,C,D = map(int,input().split())
count = 0
E = C*D/fractions.gcd(C,D)
#print(math.gcd(C,D))
def a(A,B,C):
  key = A//C +1
  if B < C:
    return 0
  else:
    return ((B-key*C)//C )+ 1
   

	
count = a(A,B,C)  + a(A,B,D)-a(A,B,E)

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


t = 4

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)
a, b, c, d = map(int, input().split())

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def main():
    left = (b -int(b/c) -int(b/d) +int(b/lcm(c,d)))
    right = ((a-1) -int((a-1)/c) -int((a-1)/d) +int((a-1)/lcm(c,d)))
    print(left - right)
main()
import math
a, b, c, d = map(int, input().split())
ac = (a - 1) // c
bc = b // c
ad = (a - 1) // d
bd = b // d
lcm = c * d // math.gcd(c,d )
acd = (a - 1) // lcm
bcd = (b - 1) // lcm
print((b-a+1)-((bc-ac)+(bd-ad)-(bcd-acd)) )
A, B, C, D = map(int, input().split())
min = min(C, D)
max = max(C, D)
c=0
d=0
e=0

def gcd(max, min):
  while min:
    max, min = min, max%min
  return max
lcm = max*min//gcd(max,min)
if A>=C:
  c = B//C-(-(-A//C))+1
if A>=D:
  d = B//D-(-(-A//D))+1
if B>=lcm:
  e = B//lcm-(-(-A//lcm))+1
print(c)
print(d)
print(e)

print(B-A+1-(c+d-e))
A,B,C,D = map(int,input().split())

import fractions

X = (C * D // fractions.gcd(C, D))
A -= 1 
ans = B - A  -  (B//C - A//C + B//D - A//D -(B//X + A//X)) 

print(int(ans))
## C - Anti-Division
import fractions
A, B, C, D = map(int, input().split())
print((B-A+1) - (int(B/C)-int((A-1)/C)) - (int(B/D)-int((A-1)/D)) + (int(B/((C*D) // fractions.gcd(C,D)))-int((A-1)/((C*D) // fractions.gcd(C,D)))))
import fractions
A, B, C, D = map(int, input().split())
n_C = int(B / C) - int((A-1) /C)
n_D = int(B / D) - int((A-1) /D)
n = (C * D) // fractions.gcd(C, D)
n_C_D = int(B / n) - int((A-1)/n)
print(B-A-n_C-n_D+n_C_D+1)
import fractions
a,b,c,d = map(int,input().split())
e = c*d//fractions.gcd(c,d)
n = b-a+1
nc = (n+a%c)//c
nd = (n+a%d)//d
ne = (n+a%e)//e
print(n-(nc+nd-ne))
from math import gcd
A, B, C, D = map(int, input().split())
E = C*D
ans = B-A+1 - (B//C-(A-1)//C + B//D-(A-1)//D - B//E-(A-1)//E)
print(ans)
import fractions
A,B,C,D=map(int,input().split())
koubaisuu = C*D//fractions.gcd(C,D)
ans = (B//C-A//C)+(B//D-A//D)-(B//koubaisuu-A//koubaisuu)
print(B-A+1-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))
print(C,D,E)
import fractions
a, b, c, d = map(int, input().split())
ans = 0
"""
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
k = b-a+1

amri_c = a % c
k_c = (k-(amri_c+1))//c + 1

amri_d = a % d
k_d = (k-(amri_d+1))//d + 1

amri_cd = a % (c*d)
k_cd = (k-(amri_cd+1))//(c*d) + 1

#print(k_c, k_d, k_cd)
ans = k-k_c-k_d+k_cd

print(ans)
from math import gcd
a, b, c, d = map(int,input().split())
c_explicit = b // c - (a - 1)// c 
d_explicit = b // d - (a - 1)// d
e = gcd(c, d)
gcl = c * d / e
e_explicit = b // gcl - (a - 1)// gcl
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)
import fractions
a,b,c,d = map(int,input().split())
l = (c*d)//fractions.gcd(c,d)
print(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))
import fractions
import math

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

NUM = B-A+1 #対象にしてる整数の個数
CD = (C*D)//fractions.gcd(C,D)

if A%C == 0:
  DivC = math.ceil(NUM/C)
else:
  NUMC = NUM-(C-A%C)
  DivC = math.ceil(NUMC/C)

if A%D == 0:
  DivD = math.ceil(NUM/D)
else:
  NUMD = NUM-(D-A%D)
  DivD = math.ceil(NUMD/D)

if A%CD == 0:
  DivCD = math.ceil(NUM/CD)
else:
  NUMCD = NUM-(CD-A%CD)
  DivCD = math.ceil(NUMCD/CD)


print(NUM - DivC -DivD + DivCD)
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=int( b//(c*d/math.gcd(c,d)) - math.ceil(a/(c*d/math.gcd(c,d))) + 1 )
print(b-a+1-(s1+s2-s12))
from math import gcd
def lcm(a, b):
    return a*b//gcd(a,b)

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

nC = (B-A)//C + 1
nD = (B-A)//D + 1
nCD = (B-A)//lcm(C,D) + 1

print((B-A+1)-(nC+nD-nCD))
import math
from decimal import Decimal

def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

A, B, C, D = map(int, input().split())
count = 0
BCcount = B // C
BDcount = B // D
ACcount = (A - 1) // C
ADcount = (A - 1) // D
l = C * D // gcd(C, D)
BCDcount = B // l
print(BCDcount)
ACDcount = (A - 1) // l
print(ACDcount)
Bcount = Decimal(B - (BCcount + BDcount - BCDcount))
Acount = Decimal((A - 1) - (ACcount + ADcount - ACDcount))
print(Decimal(Bcount - Acount))
a,b,c,d=map(int,input().split())
q=[a-1,b]
for w in range(0,2):
    x=int(q[w]/c)
    y=int(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=int(q[w]/l)
    q[w]=q[w]-x-y+z
print(q[1]-q[0])
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(unko(B,C,D)-unko(A-1,C,D))
A,B,C,D = map(int, input().split())
E = C*D
count =0
n = (A-1)//C
m = B//C
o = (A-1)//D
p= B//D
q= (A-1)//E
r= B//E
print((B-A+1) - ((m-n)+(p-o)-(r-q)))
A, B, C, D = map(int, input().split())

def gcd(x, y):
    if y == 0: return x
    return gcd(y, x%y)

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

# CとDの最大公約数
E = lcm(C, D)

F = 0
F += B // C + B // D - B // E
F -= (A - 1) // C + (A - 1) // D + (A - 1) // E

print(B - A + 1 - F)
import fractions
a, b, c, d = list(map(int, input().split()))


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


def search(n, i, j):
    l = lcm(i, j)
    return n - int(n / i) - int(n / j) + int(n / l)


print(search(b, c, d) - search(a - 1, c, d))
def main():
    a,b,c,d = map(int, input().split())
    al = b-a+1
    x = al / c
    y = al / d
    z = al / (c*d)
    an = round(x+y-z)
    #print(al, an)
    print(int(al-an))
    
if __name__ == "__main__":
    main()
a = input().split(" ")
A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])
cm = C // A
dm = D // A
cc = C // B
dc = D // B
countm = C * D // A
countc = C * D // B
print(cc + dc - cm - dm + countm - countc)
from fractions import gcd
A,B,C,D = (int(x) for x in input().split())
E = A-1
F = (C * D) / gcd(C,D)
nc = B // C
nc2 = E // C
nd = B // D
nd2 = E // D
ncd = int(B // F)
ncd2 = int(E // F)
print(B-A+1-nc+nc2-nd+nd2+ncd-ncd2)
import math

a,b,c,d = map(int,input().split())
lcm=c*d/math.gcd(c,d)

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//lcm - (a-1)//lcm

print(int(b-a+1-(s1+s2-s12)))
a, b, c, d = map(int, input().split())

q11 = (a-1)//c
q12 = (a-1)//d

q21 = b//c
q22 = b//d

q3 = (a-1)//(c*d)
q4 = b//(c*d)

print(b-(a-1) - (q21-q11) - (q22-q12) + (q4-q3))
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 int(x-(x//C+x//D-x//t_))
print(unko(B,C,D)-unko(A-1,C,D))
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-a) // lcm_n)
print(ans)
import fractions
a, b, c, d = map(int, input().split())
ans = 0

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

k = b-a+1

amri_c = a % c
k_c = (k-(amri_c+1))//c + 1

amri_d = a % d
k_d = (k-(amri_d+1))//d + 1

amri_cd = a % lcm(c, d)
k_cd = (k-(amri_cd+1))//lcm(c, d) + 1

#print(k_c, k_d, k_cd)
ans = k-k_c-k_d+k_cd

print(ans)
a,b,c,d = map(int, input().split())
import fractions
def tmp(a_): return (a_ - ((a_-1)//d + (a_-1)//c - (a_-1)//int(c*d/fractions.gcd(c,d))))
print(tmp(b)-tmp(a))
import fractions

a,b,c,d = map(int, input().split())
print(a,b,c,d)
total = b-a+1
print(total)
lcm = c*d / fractions.gcd(c,d)
x = (b//c) + (b//d) - (b//lcm)
y = ((a-1)//c) + ((a-1)//d) - ((a-1)//lcm)
print(x,y)
print(total - (x - y))
A,B,C,D=map(int,input().split())
k=0
rc=(B//C)-((A-1)//C)#割り切れる数
rd=(B//D)-((A-1)//D)#割り切れる数
rcd=(B//(C*D))-((A-1)//(C*D))
print((B-A+1)-(rc+rd-rcd))
a,b,c,d = map(int,input().split())
r = 0
f = c*d
r += int((b-a)/c)
r += int((b-a)/d)
r -= int((b-a)/f)
print((b-a)-r)
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()
import fractions

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

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

A,B,C,D = map(int,input().split())
M1 = math.floor( B / C ) + math.floor( B / D )
M2 = math.floor( (A-1) / C ) + math.floor( (A-1) / D)
N1 = math.floor( B / lcm(C,D) )
N2 = math.floor( (A-1) / lcm(C,D) )

print(B-A+1-(M1-M2-N1+N2))
import fractions
a, b, c, d=map(int, input().split())
k=fractions.gcd(c, d)
lcm=c*d//k
x=b//c - a//c
y=b//d - a//d
z=b//lcm - a//lcm
print(b-a+1-(x+y-z))
import fractions
def gcd(a,b):
   f=fractions.gcd(a,b)
   f2=a*b//f
   return f2

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

bc=b//c
bd=b//d
bcd=b//(gcd(c,d))

a=a-1

ac=a//c
ad=a//d
acd=a//(gcd(c,d))

print((b-(bc+bd)-bcd)-(a-(ac+ad)-acd))