peterverebics/CodeNet_Python_118 huggingface dataset:
from fractions import gcd
a, b, c, d = map(int, input().split())


def calc(n, div_1, div_2):
    cnt = n // div_1
    cnt += n // div_2
    lcm = div_1 * div_2 // gcd(div_1, div_2)
    cnt -= int(n // lcm)
    return n - cnt


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

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

c_count = b//c - (a-1)//c
d_count = b//d - (a-1)//d
cd_count = b//(c*d//fractions.gcd(c,d)) - (a-1)//(c*d//fractions.gcd(c,d))

print(b-a+1-(c_count+d_count-cd_count))
from fractions import gcd

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

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

    ans = 0

    bc = b // c
    bd = b // d
    cd = lcm(c,d)
    bcd = b // cd

    bcount = b - bc -bd + bcd

    ac = (a-1) // c
    ad = (a-1) // d
    acd = (a-1) //cd

    acount = (a-1) - ac -ad + acd

    print(bcount-acount)

if __name__ == '__main__':
    main()
from fractions import gcd
a, b, c, d = map(int, input().split())
ans = b - a + 1

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

a -= 1
ans = ans - (b//c) - (b//d) + (b//(lcm(c,d)))
ans = ans + (a//c) + (a//d) - (a//(lcm(c,d)))
print(ans)
def gcd(x, y):
    if y == 0:
        return x
    
    r = x % y
    return gcd(y, r)

A, B, C, D = [int(x) for x in input().split()]
if C > D:
    E = C * D // gcd(C, D)
else:
    E = C * D // gcd(D, C)

divC = B // C - (A - 1) // C
divD = B // D - (A - 1) // D
divE = B // E - (A - 1) // E
div = divC + divD - divE
ans = B - A + 1 - div

print(ans)
import sys
sys.setrecursionlimit(10 ** 9)

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

a, b, c, d = map(int, input().split())
divc = b // c - a // c
if a % c == 0:
    divc += 1
divd = b // d - a // d
if a % d == 0:
    divd += 1
    
lcm = c * d // gcd(c, d)
divlcm = b // lcm - a // lcm
if a % lcm == 0:
    divlcm += 1


div_or = divc + divd - divlcm
print(int(b - a + 1 - div_or))
from fractions import gcd

a,b,c,d = map(int,input().split())
lcm = (c*d)//gcd(c,d)
ans = 0
a -= 1

# 全体-（cで可+dで可-両方可）
ans += b-((b//c)+(b//d)-(b//lcm))
ans -= a-((a//c)+(a//d)-(a//lcm))

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

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

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

def ho(a, b, x):
  return b//x - (a-1)//x

c_ho=ho(a,b,c)
d_ho=ho(a,b,d)
cd_ho=ho(a,b,lcm(c,d))

print(b-a+1-(c_ho+d_ho)+cd_ho)
from fractions import gcd
a,b,c,d = map(int,input().split())
if a % c == 0:
    c_times = b//c - a//c + 1
else:
    c_times = b//c - a//c
#print(c_times)
if a % d == 0:
    d_times = b//d - a//d +1
else:
    d_times = b//d - a//d
#print(d_times)
lcm = c*d // gcd(c,d)
if a % lcm == 0:
    lcm_times = b//lcm - a//lcm +1
else:
    lcm_times = b//lcm - a//lcm
#print(lcm_times)
total = (b-a+1) - (c_times + d_times - lcm_times)
print(total)
A, B, C, D = map(int, input().split())
min = min(C, D)
max = max(C, D)
 
def gcd(max, min):
  while min:
    max, min = min, max%min
  return max
lcm = max*min//gcd(max,min)

#Cで割り切れる数
c = B//C-(-(-A//C))+1
#Dで割り切れる数
d = B//D-(-(-A//D))+1
#CとDで割り切れる数
e = B//lcm-(-(-A//lcm))+1

print(B-A+1-(c+d-e))
import math
A,B,C,D = (int(x) for x in input().split())
Num = B-A+1
Dup = C*D//math.gcd(C,D)
MinC  = (A+(C-A%C)%C)//C
MinD  = (A+(D-A%D)%D)//D
MinCD = (A+(Dup-A%Dup)%Dup)//Dup
OvrC  = (B+(C-B%C)%C)//C + (B%C==0)
OvrD  = (B+(D-B%D)%D)//D + (B%D==0)
OvrCD = (B+(Dup-B%Dup)%Dup)//Dup + (B%Dup==0)
CDNum = (OvrC-MinC)+(OvrD-MinD)-(OvrCD-MinCD)
print(Num-CDNum)
import fractions
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // fractions.gcd(x,y)
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))
from fractions import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)-(b//c-(a-1)//c)+(b-a+1)-(b//d-(a-1)//d)
lc=(c*d)//gcd(c,d)
ans-=(b-a+1)-(b//lc-(a-1)//lc)
print(ans)
import fractions
A, B , C , D = map(int, input().split())

bc = B // C 
bd = B // D
bcd = B // (C*D//fractions.gcd(C, D))
ans = B- (bc + bd - bcd)
ac = (A-1) // C
ad = (A-1) // D
acd = (A-1) //(C*D//fractions.gcd(C, D))
ans2=  A-1 - (ac + ad - acd)
ans = ans - ans2
print(ans)
a,b,c,d = map(int, input().split())

import fractions
lcmcd = c * d // fractions.gcd(c,d)
bc = b // c
ac = a // c
bd = b // d
ad = a // d
blcmcd = b // lcmcd
alcmcd = a // lcmcd

if a % c != 0:
    ac += 1
if a % d != 0:
    ad += 1
if a % lcmcd != 0:
    alcmcd += 1

print((b - a + 1) - ((bc - ac + 1) + (bd - ad + 1) - (blcmcd -alcmcd + 1)))
from fractions import gcd

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

A,B,C,D = list(map(int,input().split()))
C1 = B//C
C2 = (A-1)//C
C3 = B//D
C4 = (A-1)//D
C5 = B//lcm(C,D)
C6 = (A-1)//lcm(C,D)
print((B-(A-1))-((C1-C2)+(C3-C4)-(C5-C6)))
# ABC131C

def euclid(m, n):
    m0 = m = abs(m)
    n0 = n = abs(n)
    while n != 0:
        m, n = n, m % n
    qm = m0 // m
    lcm = qm * n0
    return lcm


def check(a, b, c):
    x = a // c
    y = b // c
    if x * c < a:
        x += 1
    return y - x + 1

a, b, c, d = map(int, input().split())
nc = check(a, b, c)
nd = check(a, b, d)
ncd = check(a, b, euclid(c, d))
print(b - a + 1 -(nc + nd - ncd))
a, b, c, d = list(map(int,input().split()))

def gcd(i, j):
    while j:
        i, j = j, i % j
    return i

def num_d(x, y, z):
    l, m, n = x//y, x//z, x//(y*z//(gcd(y, z)))
    return x - l - m + n


print(num_d(b, c, d) - num_d(a - 1, c, d))
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))
from fractions import gcd
a, b, c, d = map(int, input().split())

c_count = b//c
d_count = b//d
# 最小公倍数で割る
c_d = b//(c*d//gcd(c, d))

print(b - c_count - d_count + c_d - (a-1 - (a-1)//c - (a-1)//d + (a-1)//(c*d//gcd(c, d))))
from functools import reduce

def gcd(a,b):
  if a < b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

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

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

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

lcm = lcm_list([c,d])

res1 = a - 1 - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
res2 = b - (b // c + b // d - b // lcm)

print(res2 - res1)
from fractions import gcd

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

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

ans = b - a + 1
ans -= (b // c) - ((a - 1 )// c)
ans -= (b // d) - ((a - 1) // d)
ans += (b // lcm) - ((a - 1) // lcm)
print(ans)
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


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


def count(X, C, D):
    ret = X - (X//C + X//D - X//lcm(C, D))
    return ret


def main():
    A, B, C, D = map(int, input().split())
    ans = count(B, C, D) - count(A-1, C, D)
    print(ans)


if __name__ == "__main__":
    main()
A, B, C, D = map(int, input().split())
total = B - A + 1
num_C = B // C - (A-1)//C
num_D = B // D - (A-1)//D

from fractions import gcd
g = gcd(C, D)
l = C * D // g
num_CD = B//l - (A-1)//l
ans = total - (num_C + num_D - num_CD)
print(ans)
from math import gcd 

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

Bc = B // C
Bd = B // D

G = gcd(C,D)
L = int(C*D/G)

Bl = B//L

RangeB = B-(Bc+Bd-Bl)

Ac = (A-1) // C
Ad = (A-1) // D
Al = (A-1) // L

RangeA = (A-1)-(Ac+Ad-Al)

print(RangeB-RangeA)
a, b, c, d = map(int, input().split())

"""
両方に関して割り切れるものの個数から公倍数で割り切れるものを除けばいい
"""
import fractions

C = b//c - (a-1)//c
D = b//d - (a-1)//d

# 最小公倍数を求める
CD = fractions.gcd(c, d)
lcm = (c * d) // CD

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


count = C + D - G
print(b - a + 1 - count)
import sys

def S(): return sys.stdin.readline().rstrip()

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

from math import gcd

def f(n):  # 1からnまでCでもDでも割り切れない自然数の個数
    return n-n//C-n//D+n//(C*D//gcd(C,D))

print(f(B)-f(A-1))
from math import gcd
a,b,c,d = map(int, input().split())

t = c*d//gcd(c,d)
x = (a-1) - ((a-1)//c + (a-1)//d) + (a-1)//t
y = b - (b//c + b//d) + b//t

print(y-x)
import fractions

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


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


ans=B -(B//C+B//D-B//kobaisu)

ans2=(A-1)-((A-1)//C +(A-1)//D - (A-1)//kobaisu)

print(int(ans-ans2))
a, b, c, d = map(int, input().split())

from fractions import gcd
lcm = c * d // gcd(c, d)
# lcm = int(c * d / gcd(c, d)) #lcm値が微妙に異なるがこちらでも通る？
#print(lcm)

a_num = (a-1)//c + (a-1)//d - (a-1)//lcm
b_num = (b)//c + (b)//d - (b)//lcm

print(b-a+1 - (b_num - a_num))
import fractions

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


t = b//c + b//d - b//(c*d//g)
l = (a - 1)//c + (a - 1)//d - (a - 1)//(c*d//g)
ans = b - (a - 1) - t + l

print(ans)
from math import gcd
def lcm(a, b):
    return a*b//gcd(a,b)

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

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

print((B-A+1)-(nC+nD-nCD))
def gcd(a,b):
	return a if b==0 else gcd(b,a%b)
def lcm(a,b):
	return a*b//gcd(a,b)
def f(n,c,d):
	return n-n//c-n//d+n//lcm(c,d)
A, B, C, D = map(int,input().split())
print(f(B,C,D)-f(A-1,C,D))
def common_multiple(x, y):
    for i in range(2, min(x, y)+1):
        if x % i == 0 or y % i == 0:
            return common_multiple(x // i if x % i  == 0 else x, y // i if y % i == 0 else y) * i
    return x * y

a = input().split(" ")
A, B, C, D = int(a[0]) - 1, int(a[1]), int(a[2]), int(a[3])

M = common_multiple(C, D)
B0 = B // C + B // D - B // M
A0 = A // C + A // D - A // M
print(B - A - B0 + A0)
from fractions import gcd
import math

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 - math.ceil(a/c) + 1
ds = b//d - math.ceil(a/d) + 1
cds = b//cd - math.ceil(a/cd) + 1

print(all - cs - ds + cds)
import fractions
a,b,c,d = map(int,input().split())
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
ans = (b-a+1)-(x+y-z)
print(ans)
import fractions

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

cd = (c * d) // fractions.gcd(c, d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = (a-1) // c
a_d = (a-1) // d
a_cd = (a-1) // cd

ans = b - b_c - b_d + b_cd - (a-1) + a_c + a_d - a_cd

print(ans)
import fractions
a,b,c,d=map(int, input().split())
ans = 0
f=fractions.gcd(c,d)
f2=c*d//f

bf = b//f2
af = (a-1)//f2

cb = b//c
ca = (a-1)//c

db = b//d
da = (a-1)//d

print(b-a+1-(cb-ca)-(db-da)+(bf-af))
import fractions
a,b,c,d=map(int,input().split())
t=b//d-((a-1)//d)
s=b//c-((a-1)//c)
p=fractions.gcd(d,c)
q=c*d//p
u=b//q-((a-1)//q)
print(b-a+1-(t+s-u))
import fractions

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

c_d = (c * d) // fractions.gcd(c, d)

a -= 1

tmp_b = b - (b//c + b//d - b//c_d)
tmp_a = a - (a//c + a//d - a//c_d)

print(tmp_b-tmp_a)
import fractions
a, b, c, d = [int(i) for i in input().split()]
"""
print(b // c, b // d, b // ((c * d) // fractions.gcd(c,d)), (a-1) // c, (a-1) // d, (a-1) // ((c * d) // fractions.gcd(c,d)))
print((c * d) // fractions.gcd(c,d))
"""
print(
    b - a + 1 - 
    (b // c + b // d 
        - b // ((c * d) // fractions.gcd(c,d)) 
    - (a-1) // c - (a-1) // d 
        + (a-1) // ((c * d) // fractions.gcd(c,d)))
)
def gcd(m,n):
    while (m % n != 0):
        n,m = m%n,n
    return(n)

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

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

a -= 1
n1 = b - b // c - b // d + b // lcm(c,d)
n2 = a - a // c - a // d + a // lcm(c,d)


print(n1 - n2)
import fractions
a,b,c,d=map(int,input().split())
total=b-a+1
cdiv=b//c-(a-1)//c
ddiv=b//d-(a-1)//d
CDdiv=(c*d)//fractions.gcd(c,d)
cddiv=b//(CDdiv)-(a-1)//(CDdiv)
print(total-cdiv-ddiv+cddiv)
from fractions import gcd
a, b, c, d = map(int, input().split())
lcm = c * d // gcd(c, d)
cnt = b // c + b // d - b // lcm - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
print(b - a + 1 - cnt)
import fractions
a,b,c,d=map(int,input().split())
a-=1
y=int(c*d/fractions.gcd(c,d))

p=a-((a//c)+(a//d)-(a//y))

q=b-((b//c)+(b//d)-(b//y))

print(int(q-p))
import math
import fractions
A, B, C, D = map(int, input().split())

#B以下の整数の個数
x = B - (B // C) - (B // D)
#C,Dの最大公約数を求める
l = fractions.gcd(C, D)
#C,Dの最小公倍数を求める
temp = C * D // l 
#C,Dで重複して引いた数を足し合わせる
x += (B // temp)

#同様にA - 1以下の整数のうちの個数も求める
a = A - 1
y = a - (a // C) - (a // D)
y += (a // temp)

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

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

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

a, b, c, d = map(int, sys.stdin.readline().split())

def count(n):
    return n - (n // c + n // d - n // lcm(c, d))

def main():
    print(count(b) - count(a-1))
    
if __name__ ==  '__main__':
    main()
a, b, c, d = map(int, input().split())


def calc(x, n):
    return x // n


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


l = c * d // gcd(c, d)
x = (a - 1) - calc(a - 1, c) - calc(a - 1, d) + calc(a - 1, l)
y = b - calc(b, c) - calc(b, d) + calc(b, l)
print(y - x)
def baisu(n, a):
  return n // a

def baisu2(n, m, a):
  return baisu(m, a)-baisu(n-1, a)

import fractions

def lcm(k):
    ans = k[0]
    for i in range(1, len(k)):
        ans = ans * k[i] // fractions.gcd(ans, k[i])
    return ans

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

cbaisu = baisu2(a, b, c)
dbaisu = baisu2(a, b, d)
cdbaisu = baisu2(a, b, lcm([c, d]))

print(b-a+1-cbaisu-dbaisu+cdbaisu)
a,b,c,d = map(int,input().split())
from fractions import gcd
cd_gcd = gcd(c,d)
lcm= c*d // cd_gcd


ans = []
for i in (a-1,b):
  ans.append(int(i/c) + int(i/d) - int(i/lcm))

print(b-a - (ans[1]-ans[0]))
a,b,c,d = map(int, input().split())
import fractions
r = b-a+1
g = c * d // fractions.gcd(c, d)
ans_c = b//c - (a-1)//c
ans_d = b//d - (a-1)//d
ans_r = b//r - (a-1)//r
print(r - ans_c - ans_d + ans_r)
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-tc+tcd)
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))
from fractions import gcd
A, B, C, D = map(int, input().split())

U = B - A + 1
U_c = U // C
U_d = U // D
U_cd = U // (C * D // gcd(C, D))

ans = U - (U_c + U_d - U_cd)
if A % 4 == 0 or B % 4 == 0:
    ans -= 1
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:
  div1+=1
if a%d ==0:
  div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print(mm-roger)
import math

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

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

def num(i):
  ans = int(b/i) - int(a/i)
  if a % i == 0:
    ans +=1
  return ans

lcm_num = num(lcm)

cd_num  = num(c) + num(d)

num = cd_num - lcm_num

print(b-a+1-num)
from fractions import gcd

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

lcm = int(C*D / gcd(C, 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)
import fractions
A,B,C,D = map(int,input().split())
S = B-A+1
print(S-(S//C + S//D - S//((C*D)//fractions.gcd(C,D))))
a,b,c,d=list(map(int,input().split()))
import math
def yakusuu(n):
  return n//c+n//d-n//(c*d/math.gcd(c,d))

print(int(b-a+1-(yakusuu(b)-yakusuu(a-1))))
from fractions import gcd
a,b,c,d = map(int,input().split())

lcm = c*d / gcd(c,d)
x = lcm
div = 0
while a <= x <= b:
    div += 1
    x  += lcm
    
cdiv = b//c - (a-1)//c
ddiv = b//d - (a-1)//d

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

from fractions import*
upto_B=B-(B//C+B//D-B//(C*D//gcd(C,D)))
upto_A=A-1-((A-1)//C+(A-1)//D-(A-1)//(C*D//gcd(C,D)))

print(upto_B-upto_A*(A>2))
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)

a,b,c,d = map(int,input().split())
A = a-((a//c) + (a//d) - a//lcm(c,d))
B = b-((b//c) + (b//d) - b//lcm(c,d))
print(B-A)
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
    elif ((d*c)/2) % c == 0 and ((d*c)/2) % d == 0:
        di = d*c//2
    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())
ci = (b//c) - (a//c)
di = (b//d) - (a//d)
e = c * d // gcd(c, d)
cdi = (b//e) - (a//e)
print(b-(a-1)-(ci+di-cdi))
from math import ceil

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


Cdiff = ceil(B/C) - ceil((A-1)/C)
Ddiff = ceil(B/D) - ceil((A-1)/D)

CDdiff = ceil(B/(C*D) ) - ceil((A-1)/(C*D))

res = Cdiff+Ddiff-CDdiff
print((B-A)-res)
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 (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 fractions
import math
a,b,c,d = map(int, input().split())
x1 = (a-1)//c
x2 = b//c
x = x2-x1
y1 = (a-1)//d
y2 = b//d
y = y2-y1
z1 = (a-1)//((c*d)/fractions.gcd(c,d))
z2 = b//((c*d)/fractions.gcd(c,d))
z = z2-z1
print(int((b-a+1)-x-y+z))
import fractions
a, b, c, d = map(int, input().split())
ans = 0

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

def k(x):
    return x - (x//c + x//d - x//lcm(c, d))

print(k(b)-k(a))
A,B,C,D=map(int,input().split())
print(A,B,C,D)

from math import*
upto_B=B-(B//C+B//D-B//(C*D//gcd(C,D)))
upto_A=A-1-((A-1)//C+(A-1)//D-(A-1)//(C*D//gcd(C,D)))

print(upto_B-upto_A*(A>2))
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(B-A+1-nc-nd+ncd)
a,b,c,d = map(int, input().split())
count = 0

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a
 #最小公倍数
def lcm(a,b):
    return a*b // gcd(a,b)

gcd_num = lcm(c,d)

#a
a_count = a // c
a_count = a_count + (a//d)
a_count = a_count - (a//gcd_num)

#b
b_count = b // c
b_count = b_count + (b//d)
b_count = b_count - (b//gcd_num)

print((b-a)-  b_count + a_count)
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 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())

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

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

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

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

print(ans)
a, b, c, d = map(int, input().split())
if a != 0:
    xc = int((a-1)/c)
    yc = int(b/c)
    xd = int((a-1)/d)
    yd = int(b/d)
    xcd = int((a - 1) / (c * d))
    ycd = int(b / (c * d))
else:
    xc = int((a)/c)
    yc = int(b/c)
    xd = int((a)/d)
    yd = int(b/d)
    xcd = int((a) / (c * d))
    ycd = int(b / (c * d))
print(b - a + 1 -((yc - xc) + (yd - xd) - (ycd - xcd)))
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 = c*d//math.gcd(c,d)

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

print(int(ans))
from fractions import gcd

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

def solve():
    A,B,C,D = map(int, input().split())
    c = B//C - A//C
    if A % C == 0:
        c += 1
    d = B//D - A//D
    if B % C == 0:
        d += 1
    r = lcm(C,D)
    e = B//r - A//r
    ans = (B-A+1) - (c+d-e)
    if ans < 0:
        return 0
    return ans

print(solve())
A,B,C,D = list(map(int,input().split()))
count = 0

for i in range(A,B):
    x = i+1
    c = (i+1)%C
    d = (i+1)%D
    if A <= x:
        if c==0 or d==0:
            count += 1

print(B-A-count)
import sys
import math
from fractions import gcd

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

a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d) 
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h 
print(n)
A,B,C,D = map(int, input().split())

def calc(a,x):
    return int(a/x)

print(B - A + 1 - (calc(B, C) - calc(A-1, C) + calc(B, D) - calc(A-1, D) - (calc(B, C*D) - calc(A-1, C*D))))
import fractions
A, B, C, D = map(int, input().split())
if B > C:
    n_C = int(B / C) - int((A-1) /C)
else:
    n_C = 0
if B > D:
    n_D = int(B / D) - int((A-1) /D)
else:
    n_D = 0
n = C * D // fractions.gcd(C, D)
if B > n:
    n_C_D = int(B / n) - int((A-1)/n)
else:
    n_C_D = 0
print(B-A-n_C-n_D+n_C_D+1)
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = int(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()
a, b, c, d = map(int, input().split())

b_ = b
b -= b // c
b -= b // d

a_ = a
a -= a // c
a -= a // d

if b_ % a_ == 0:
    b += 1

print(b - a)
import fractions
a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
l=int(c*d/g)
x=b-a
ac=a/c
bc=b/c
ad=a/d
bd=b/d
al=a/l
bl=b/l
if ac==int(ac) or bc==int(bc):
    cans=x//c+1
else:
    cans=x//c
if ad==int(ad) or  bd==int(bd):
    dans=x//d+1
else:
    dans=x//d
if al==int(al) or  bl==int(bl):
    lans=x//l+1
else:
    lans=x//l
        
re=int(x+1-(cans+dans-lans))
print(re)
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
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())

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

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

A, B, C, D = map(int, input().split())
total = B - A + 1
CD = lcm(C, D)

C_count = math.floor(B / C) - math.floor((A-1) / C)
D_count = math.floor(B / D) - math.floor((A-1) / D)
CD_count = math.floor(B / CD) - math.floor((A-1) / CD)

result = total - C_count - D_count + CD_count
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

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

def solve():
    A,B,C,D = map(int, input().split())
    c = B//C - A//C
    if A % C == 0:
        c += 1
    d = B//D - A//D
    if B % C == 0:
        d += 1
    r = lcm(C,D)
    e = B//r - A//r

    return (B-A+1) - (c+d-e)

print(solve())
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
print(answer)
import math
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1
n_c=1+(b-c+1)//c-(a+c-1)//c+1
n_d=1+(b-d+1)//d-(a+d-1)//d+1
cd=c*d/fractions.gcd(c,d)
n_cd=1+(b-cd+1)//cd-(a+cd-1)//cd+1
print(base-n_c-n_d+n_cd)