peterverebics/CodeNet_Python_118 huggingface dataset:
import fractions
import sys
sys.setrecursionlimit(10**8)


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


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


def solve(v):
    return v - v // c - v // d + v // lcm2(c, d)


print(solve(b) - solve(a-1))
import math


def cnt(a: int, k: int):
    return a // k


def num(a, c, d):
    m_a_c = cnt(a, c)
    m_a_d = cnt(a, d)
    m_a_cd = cnt(a, c * d // math.gcd(c, d))
    return a - m_a_c - m_a_d + m_a_cd


a, b, c, d = map(int, input().split())
print(num(b, c, d) - num(a-1, c, d))
import fractions
A, B, C, D = map(int, input().split())
n_C = B // C - (A-1) //C
n_D = B // D - (A-1) //D
n = (C * D) // fractions.gcd(C, D)
n_C_D = B // n - (A-1)// n
print(B-A-n_C-n_D+n_C_D+1)
from fractions import gcd

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

cnt_c = B//C - (A-1)//C
cnt_d = B//D - (A-1)//D

lcm = C * D // gcd(C, D)
cnt_cd = B//lcm - (A-1)//lcm

divisible = cnt_c + cnt_d - cnt_cd
print(B-A+1-divisible)
import sys
import fractions
input = lambda: sys.stdin.readline().rstrip()


def count_div(N, C, D):

    t = N // C + N // D - N // (C * D // fractions.gcd(C, D))
    return N - t


def solve():

    A, B, C, D = map(int, input().split())
    ans = count_div(B, C, D) - count_div(A - 1, C, D)
    print(ans)


if __name__ == '__main__':
    solve()
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 int(a*b / gcd(a,b))
cnt = 0
quo_c = b//c - (a-1)//c
quo_d = b//d - (a-1)//d
quo_cd = b//lcm(c,d) - (a-1)//lcm(c,d)
print(b - (a-1) - quo_c - quo_d + quo_cd)
from fractions import gcd
a,b,c,d=map(int,input().split())
count=b-a+1
temp1=b//c-(a-1)//c
temp2=b//d-(a-1)//d
temp3=b//int((c*d)/gcd(c,d))-(a-1)//int((c*d)/gcd(c,d))
print(int(count-temp1-temp2+temp3))
def gcd(x,y):
  while y:
    x,y = y,x%y
  return x

def calc(x,a,b,l):
  return x - (x//a) - (x//b) + (x//l)

A,B,C,D = map(int,input().split())
lcm = C*D // gcd(C,D)
print(calc(B,C,D,lcm) - calc(A-1,C,D,lcm))
def resolve():
    import math
    A, B, C, D = [int(i) for i in input().split()]
    A -= 1
    LCMCD = C * D // math.gcd(C, D)
    ans = (B - B // C - B // D + B // LCMCD) - \
          (A - A // C - A // D + A // LCMCD)
    print(ans)


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


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


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


a = (A-1) - ((A-1) // C + (A-1) // D - (A-1) // lcm(C, D))
b = B - (B // C + B // D - B // lcm(C, D))
print(b-a)
from fractions import gcd
from functools import reduce

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

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

tmp = B // C + B // D - A//C - A // D
if A%C == 0:
    tmp += 1
if A%D == 0:
    tmp += 1
lcm = lcm_base(C, D)
tmp -= (B//lcm - A//lcm)
if A%lcm == 0:
    tmp -= 1
print(B-A+1-tmp)
import math
A, B, C, D = map(int, input().split())
c = B // C - A // C + int(A % C == 0)
d = B // D - A // D + int(A % D == 0)
E = int((C * D) / math.gcd(C, D))
e = B // E - A // E + int(A % E == 0)
print(B - A + 1 - c - d + e)
A, B, C, D = map(int,input().split())

def gcd(x,y):
    if x<y:
        x, y = y, x
    r = x%y
    while r!=0:
        x = y
        y = r
        r = x%y
    return y

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

L = lcm(C,D)

lenB = B-(B//C+B//D-B//L)
A-=1
lenA = A-(A//C+A//D-A//L)
print(lenB-lenA)
import sys
input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def main():
    A, B, C, D = map(int, input().split())
    g = gcd(max(C,D),min(C,D))
    l = C*D//g
    NB = B - B//C - B//D + B//l
    NA = (A-1) - (A-1)//C - (A-1)//D + (A-1)//l
    ans = NB - NA
    print(int(ans))

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

print(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))))
import math
import fractions
def main():
    A, B, C, D = map(int, input().split())
    
    n_U = (B-A+1)
    n_C = B//C - (A-1)//C
    n_D = B//D - (A-1)//D
    LCM = (C*D)//fractions.gcd(C, D)
    n_CD = B//LCM - (A-1)//LCM
    
    print(n_U - n_C - n_D + n_CD)

if __name__ == "__main__":
    main()
# 1時間位はかかった
# lcmはfloatで返され、floatのまま処理を続けると値が正確でなくなる点になかなか気づけなかった

import fractions

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


def dev(n):
    return b // n - -(-a // n) + 1

print(dev(1) - dev(c) - dev(d) + dev(c * d//gcd(c,d)))
import fractions

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

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

B2=B-B//C-B//D+B//lcm(C,D)
A2=(A-1)-(A-1)//C-(A-1)//D+(A-1)//lcm(C,D)

print(B2-A2)
import fractions
a,b,c,d = map(int,input().split())
k = c*d//fractions.gcd(c,d)
sc = b//c-(a-1)//c
sd = b//d-(a-1)//d
sk = b//k-(a-1)//k
print(b-a+1-sc-sd+sk)
import math
 
def lcm(a, b):
    return (a*b)//math.gcd(a, b)
 
a, b, c, d = map(int, input().split())
e = lcm(c, d)
 
total = b - (a - 1)
cc = b//c - (a-1)//c
dd = b//d - (a-1)//d
ee = b//e - (a-1)//e
 
ans = total - cc - dd + ee
print(ans)
a,b,c,d = map(int,input().split())
from math import gcd
e  =c*d//gcd(c,d)
xa = a//c if a%c else a//c - 1
xb = b//c
ya = a//d if a%d else a//d - 1
yb = b//d
za = a//e if a%e else a//e - 1
zb = b//e
x = xb-xa
y  = yb-ya
z = zb-za
print(b-a+1-x-y+z)
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-1)//c + b//d - (a-1)//d -b//l + (a-1)//l))
import math
a,b,c,d=map(int,input().split())
x=b-b//c-b//d+b//(c*d//math.gcd(c,d))
y=(a-1)-(a-1)//c-(a-1)//d+(a-1)//(c*d//math.gcd(c,d))
print(x-y)
import math
import fractions

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

Cans = (B // C  + (-A // C)) + 1
Dans = (B // D  + (-A // D)) + 1

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

CDans = (B // CDlcm  + (-A // CDlcm)) + 1

ans = (B - A + 1) - (Cans + Dans - CDans)
print(ans)
import math
from  fractions import gcd

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

A,B,C,D = map(int,input().split())
d_cnt = B//D-(A-1)//D
c_cnt = B//C-(A-1)//C
cd = lcm(C,D)
cd_cnt = B//cd-(A-1)//cd
print(B-A+1-(c_cnt+d_cnt-cd_cnt))
A, B, C, D = map(int, input().split())
X, Y = C, D

while True:
  if X > Y:
    t = Y
    Y = X % Y
    X = t
  else:
    Y = Y % X
  if Y == 0:
    break;

a = (A - 1) - (A - 1)//C - (A - 1)//D + (A - 1)//(C*D//X)
b = B - B//C - B//D + B//(C*D//X)

print(b - a)
import math

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

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

ac=a//c
ad=a//d
acd=a//lcm
bc=b//c
bd=b//d
bcd=b//lcm

A=a-ac-ad+acd
B=b-bc-bd+bcd

if a%c==0 or a%d==0:
  print(B-A)
else:
  print(B-A+1)
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 = C * D // 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(int(ans))
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-1)//e)
b = int(b//e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))
def calc(a, b):
    x = max(a, b)
    y = min(a, b)
    while True:
        c = x % y
        if c == 0:
            break
        x = y
        y = c
    return y

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

E = int(C * D / calc(C, D))
l = int(B - B // C - B // D + B // E)
m = int((A-1) - (A-1) // C - (A-1) // D + (A-1) // E)

print(l-m)
from fractions import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = A // C, A // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), A // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
if(A % C != 0): ans += 1
print(ans)
import fractions

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

lcm = (C * D)//fractions.gcd(C, D)
area = B - A + 1
Carea = (B // C - (A-1) // C)
Darea = (B // D - (A-1) // D)
CDarea = (B//lcm - (A-1)//lcm)

print(area - (Carea+Darea-CDarea))
import fractions
A, B, C, D = map(int, input().split())

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

c = B // C - (A - 1) // C 
d = B // D - (A - 1) // D 
e = B // E - (A - 1) // E
ans = B - A - c - d + e + 1
print(ans)
from fractions import gcd
 
A, B, C, D = map(int, input().split())
t = C * D // gcd(C, D)
print((B - (A - 1)) - (B//C + B//D - B//t) + ((A-1)//C + (A-1)//D - (A-1)//t))
import sys
input = sys.stdin.readline

def f(x):
    return B//x-(A-1)//x

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

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

A, B, C, D = map(int, input().split())
print(B-A+1-f(C)-f(D)+f(lcm(C, D)))
from math import gcd
from decimal import Decimal as dec 
a, b, c, d = map(dec,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(int(c), int(d))
e = dec(e)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)
import math
a,b,c,d=map(int,input().split())
p = c * d // math.gcd(c, d)
x = b//c + b//d - b//p -((a-1)//c + (a-1)//d - (a-1)//p)
ans = b-a+1 -x
print(ans)
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

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

A, B, C, D = lr()
cnt_divided_C = B // C - (A-1) // C
cnt_divided_D = B // D - (A-1) // D
x = C * D // gcd(C, D)
cnt_divided_CD = B // x - (A-1) // x
answer = B - (A-1) - (cnt_divided_C + cnt_divided_D - cnt_divided_CD)
print(answer)
from math import gcd
A, B, C, D = map(int,input().split())

lcm = C*D // gcd(C,D)
a = (A-1)//C + (A-1)//D - (A-1)//lcm
b = B//C + B//D - B//lcm

print(B-A+1-b+a)
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 = (a-1)//c
cb = b//c
da = (a-1)//d
db = b//d
cda = (a-1)//lcm(c,d)
cdb = b//lcm(c,d)
ans -= (cb+db-cdb) - (ca+da-cda)
print(ans)
import math

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

a -= 1

x = a // c
y = a // d
z = a // lcm

ans1 = a - (x + y - z)

x = b // c
y = b // d
z = b // lcm

ans2 = b - (x + y - z)

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

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

def amari(x,y):
    return x//y if x%y==0 else x//y+1

cnum=b//c-amari(a,c)+1
dnum=b//d-amari(a,d)+1
cdnum=b//lcm(c,d)-amari(a,lcm(c,d))+1

print(b-a+1-cnum-dnum+cdnum)
import fractions

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


i = (a-1) // c #aのcの約数の数
j = b // c #bのcの約数の数
k = (a-1) // d #aのdの約数の数
l = b // d #bのdの約数の数
m = (a-1) // (e) #aのc*dの約数の数
n = b // (e) #bのc*dの約数の数

x = (j-i) + (l-k) - (n-m)
y = b - a + 1
print(y-x)
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
E=C*D//gcd(C,D)
print(B-B//C-B//D+B//E-A+A//C+A//D-A//E)
a,b,c,d=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=map(int,input().split())
nc=(b//c)-((a-1)//c)
nd=(b//d)-((a-1)//d)

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

ncd=(b//q)-((a-1)//q)
r=nc+nd-ncd
ans=(b-a+1)-r
print(ans)
import fractions
A, B, C, D = map(int, input().split())

l=C*D//fractions.gcd(C,D)
underB = B- (B//C+B//D-B//l)
underA = (A-1)- ((A-1)//C+(A-1)//D-(A-1)//l)
#print(underB, underA)
print(underB-underA)
A, B, C, D = map(int, input().split())

from fractions import gcd
total = B - A + 1
c_multiples = B // C + 1 - (A+C-1) // C
d_multiples = B // D + 1 - (A+D-1) // D
lcm = C * D // gcd(C, D)
lcm_multiples = B // lcm + 1 - (A+lcm-1) // lcm

ans = total - c_multiples - d_multiples + lcm_multiples
print(ans)
a,b,c,d = map(int,input().split())
a -= 1
from fractions import gcd
divac = a // c
divad = a // d
divbc = b // c
divbd = b // d
divacd = a // (c*d//gcd(c,d))
divbcd = b // (c*d//gcd(c,d))
Acd = divac + divad - divacd
Bcd = divbc + divbd - divbcd
wareru = Bcd - Acd
ans = b-a-wareru
print(ans)
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from fractions import gcd
def resolve():
    a, b, c, d = map(int, input().split())
    L = c // gcd(c, d) * d
    a -= 1
    S = b - b // c - b // d + b // L
    T = a - a // c - a // d + a // L
    print(S - T)
resolve()
a,b,c,d=map(int,input().split())

import fractions

def cnt_div(n,c,d):
    #n以下の整数で，cでもdでも割り切れない数の個数
    tmp1 = n // c
    tmp2 = n // d
    tmp3 = n // (c*d//fractions.gcd(c,d)) #最大公約数
    return n-(tmp1+tmp2-tmp3)

print(cnt_div(b,c,d)-cnt_div(a-1,c,d))
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1
n_c=b//c-(a+c-1)//c+1
n_d=b//d-(a+d-1)//d+1
cd=c*d // fractions.gcd(c,d)
n_cd=b//cd-(a+cd-1)//cd+1
print(base-n_c-n_d+n_cd)
import math
a, b, c, d = map(int, input().split())


def fn(n):
    lcm = (c * d) // math.gcd(c, d)
    return (n - (n // c) - (n // d) + (n // lcm))


print(fn(b)-fn(a-1))
from fractions import gcd
a, b, c, d = map(int, input().split())
l = c // gcd(c, d) * d
def f(x): # # of num lt or eq to x undivisable by c nor d
    return x - x // c - x // d + x // l
print(f(b) - f(a - 1))
import math
A, B, C, D = map(int, input().split())

c = (B//C) - ((A+C-1)//C) + 1
d = (B//D) - ((A+D-1)//D) + 1
lcm = int(C * D / math.gcd(C, D))
m = (B//lcm) - ((A+lcm-1)//lcm) + 1
ans = (B-A+1) - (c+d-m)
print(int(ans))
import fractions

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

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

div_c = (B // C) - (A // C)
if A // C != 0 and A % C == 0:
    div_c += 1
div_d = (B // D) - (A // D)
if A // D != 0 and A % D == 0:
    div_d += 1
div_cd = (B // (lcm)) - (A // (lcm))
if A // (lcm) != 0 and A % lcm == 0:
    div_cd += 1

ans = (B - A + 1) - (div_c + div_d - div_cd)
print(ans)
from fractions import gcd
a,b,c,d=map(int,input().split())
print(b-a+1-(b//c+b//d-b//(c*d//gcd(c,d))-((a-1)//c+(a-1)//d-(a-1)//(c*d//gcd(c,d)))))
import math
A, B, C, D = map(int, input().split())

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

def num_multi(num, lb, ub): # [lb, ub]にnumの倍数がいくつあるのかを返す
    lR = lb // num
    lQ = lb % num

    uR = ub // num
    # uQ = ub % num

    ans = uR - lR
    if lQ == 0:
        ans += 1

    return ans

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

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

lcm = C*D//gcd(C,D)

def n_mul(c):
  if A%c==0 and B%c==0:return(B//c-A//c+1)
  elif A%c==0 and B%c!=0:return(B//c-A//c+1)
  elif A%c!=0 and B%c==0:return(B//c-A//c)
  else:return(B//c-A//c)

print(B-A+1-(n_mul(C)+n_mul(D)-n_mul(lcm)))
import fractions
a, b, c, d = map(int, input().split())
lcm = (c*d)//fractions.gcd(c, d)
a -= 1
ans1 = b - b//c - b//d + b//lcm
ans2 = a - a//c - a//d + a//lcm
print(ans1 - ans2)
import math
a,b,c,d = map(int,input().split())
min_c = (a-1)//c
max_c = b//c
min_d = (a-1)//d
max_d = b//d
tmp = (c * d) // math.gcd(c, d)
min_cd = (a-1)//tmp
max_cd = b//tmp

#print(a,b,c,d)
#print(min_c,max_c)
#print(min_d,max_d)
#print(min_cd,max_cd)
print(b-(a-1)-(max_c-min_c)-(max_d-min_d)+(max_cd-min_cd))
import fractions
A,B,C,D = map(int,input().split())

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

LCM = lcm(C,D)
BC = B // C
BD = B // D
BCD = B // LCM
AC = (A-1) // C
AD = (A-1) // D
ACD = (A-1) // LCM
x = B - BC - BD + BCD
y = (A-1) - AC - AD + ACD
print(x - y)
# gcd: 最大公約数
def gcd(x,y):
  while y:
    x, y = y, x%y
  return x
# lcm: 最小公約数
def lcm(x,y):
  return x*y//gcd(x,y)
a,b,c,d=map(int,input().split())
a-=1
e=lcm(c,d)
tc=b//c-a//c
td=b//d-a//d
te=b//e-a//e
print(b-a-tc-td+te)
from math import ceil
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

nd = b//d-a//d
if a%d==0:
    nd += 1

ne = b//e-a//e
if a%e==0:
    ne += 1

print(b-a+1-nc-nd+ne)
import math
A,B,C,D = map(int, input().split())
ans1 = B-B//C-B//D
g = math.gcd(C, D)
l = C*D//g
ans1 = ans1+B//l
ans2 = A-1-(A-1)//C-(A-1)//D
ans2 = ans2+(A-1)//l
ans = ans1-ans2
print(int(ans))
a,b,c,d = map(int,input().split())
x = b//c - -(-a//c) + 1
y = b//d - -(-a//d) + 1

import fractions
cd = c * d // fractions.gcd(c,d)
z = b//(cd) - -(-a//(cd)) + 1

print((b-a+1) - (x+y-z))
import math
def readinput():
    a,b,c,d=map(int,input().split())
    return a,b,c,d

def main(a,b,c,d):
    lcm=c*d//math.gcd(c,d)
    #print(lcm)
    return b-a+1 - ( b//c-(a-1)//c + b//d-(a-1)//d - ( b//lcm - (a-1)//lcm ) )


if __name__=='__main__':
    a,b,c,d=readinput()
    ans=main(a,b,c,d)
    print(ans)
a, b, c, d = map(int, input().split())

from fractions import gcd

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

ac = (a - 1) // c
ad = (a - 1) // d
acd = (a - 1) // lcm(c, d)
x = (a - 1) - ac - ad + acd

bc = b // c
bd = b // d
bcd = b // lcm(c, d)
y = b - bc - bd + bcd

ans = y - x
print(ans)
import fractions

a,b,c,d=[int(x) for x in input().split()]

def count(n):
  r=b//n
  l=a//n
  if a%n!=0:
     l+=1
  return r-l+1

ans=b-a+1-count(c)-count(d)+count(c*d//fractions.gcd(c,d))

print(ans)
#print(b-a+1,count(c),count(d),count(c*d//fractions.gcd(c,d)))
# -*- coding: utf-8 -*-
# モジュールのインポート
from fractions import gcd

# 標準入力の取得
A, B, C, D = list(map(int, input().split()))


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


# 求解処理
div_C = (B // C) - ((A - 1) // C)
div_D = (B // D) - ((A - 1) // D)
lcm_CD = lcm(C, D)
div_lcm_CD = (B // lcm_CD) - ((A - 1) // lcm_CD)
result = (B - A + 1) - div_C - div_D + div_lcm_CD

# 結果出力
print(result)
import math
a,b,c,d = map(int,input().split())
a -= 1
ans = b-a
ans -= b//c - a//c
ans -= b//d - a//d
e = c*d//math.gcd(c,d)
ans += b//e - a//e
print(ans)
A ,B ,C ,D = (map(int , input().split()))
from fractions import gcd
def lcm(x,y):
    return (x*y) // gcd(x,y)
koubaisuu = lcm(C,D)
e = B//C
f = B//D
g = B//(koubaisuu)
h = B-((e+f)-g)
AA = A - 1
ee = AA//C
ff = AA//D
gg = AA//(koubaisuu)
hh = AA-((ee+ff)-gg)
print(h-hh)
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-1))
# 最大公約数
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

# 最小公倍数
def lcm(m, n):
    return m//gcd(m, n)*n

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

def f(n,C=C,D=D):
    return n - (n//C + n//D - n//lcm(C,D))
print(f(B)-f(A-1))
from math import gcd
a, b, c, d = map(int, input().split())
lcm = c*d//gcd(c, d)
cc = b//c - (a//c - (a%c==0))
cd = b//d - (a//d - (a%d==0))
clcm = b//lcm - (a//lcm - (a%lcm==0))
print(b-a+1 - (cc + cd - clcm))
a, b, c, d = map(int, input().split())
 
def gcd(x, y):
    if y > x:
        return gcd(y, x)
    if x % y == 0:
        return y
    return gcd(y, x%y)
 
cd = c * d // gcd(c, d)
 
b_div = b - b//c - b//d + b//cd
a_div = a-1 - (a-1)//c - (a-1)//d + (a-1)//cd
 
print(b_div - a_div)
import fractions
A,B,C,D = map(int,input().split())

ans = B-A+1

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

ans -= B//C

ans -= B//D

ans += B//LCM

ans += (A-1)//C

ans += (A-1)//D

ans -= (A-1)//LCM
print(ans)
def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)
 
def lcm(a, b):
    return a // gcd(a, b) * b

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

n = b - a + 1
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//lcm(c,d) - (a-1)//lcm(c,d)

print(n - n_c - n_d + n_cd)
import sys
from fractions import gcd
input = sys.stdin.readline
A, B, C, D = map(int, input().split())
l = (A - 1) // C + (A - 1) // D - (A - 1) // (C * D // gcd(C, D))
r = B // C + B // D - B // (C * D // gcd(C, D))
print(B - A + 1 - (r - l))
def main():
    A, B, C, D = map(int, input().split())
    num_C_div = B // C - (A - 1) // C
    num_D_div = B // D - (A - 1) // D
    CD_lcm = lcm(C, D)
    num_CandD_div = B // (CD_lcm) - (A - 1) // (CD_lcm)
    num_CorD_div = num_C_div + num_D_div - num_CandD_div
    print((B - A + 1) - num_CorD_div)


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


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


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

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)
E = lcm(C,D)
print( (B-A+1)-((B//C-A//C + (A%C==0)) + (B//D-A//D+ (A%D==0)) - (B//E-A//E+ (A%E==0))))
import fractions

a,b,c,d=map(int,input().split())
def cal(x,div1,div2):
    ret1=x//div1
    ret2=x//div2
    ret3=x//int(((div1*div2)/fractions.gcd(div1,div2)))
    return x-(ret1+ret2-ret3)
print(cal(b,c,d)-cal(a-1,c,d))
from math import gcd


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


a, b, c, d = map(int, input().split())
e = lcm(c, d)
num_e = b // e - (a - 1) // e
num_c = b // c - (a - 1) // c
num_d = b // d - (a - 1) // d
num_can_div = num_c + num_d - num_e

print((b - a) - num_can_div + 1)
def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

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

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

a, b, c, d = map(int, input().split())
print(b - a + 1 - func(c, a, b) - func(d, a, b) + func(lcm(c, d), a, b))
a, b, c, d = map(int, input().split())
cdiv = c
ddiv = d
while ddiv > 0:
  cdiv, ddiv = ddiv, cdiv % ddiv
M = c*d//cdiv

mnd = M-(c+d)//cdiv+1
ad = (a-1) % M
bd = b % M

print(mnd*(b//M)+bd-bd//c-bd//d-mnd*((a-1)//M)-ad+ad//c+ad//d)
import math

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

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

def lcm_(x,y):
    return (x * y) // gcd_(x, y)

def f(x, y):
    return x // y

lcm = lcm_(C, D)
ret1 = A - 1 - f(A - 1, C) - f(A - 1, D) + f(A - 1, lcm)
ret2 = B - f(B, C) - f(B, D) + f(B, lcm)
ans = ret2 - ret1
print(ans)
A,B,C,D=map(int, input().split())

import fractions
lcm = C*D//fractions.gcd(C,D)
min_ = A-1
print((B-min_)-((B//C-min_//C)+(B//D-min_//D)-(B//lcm-min_//lcm)))
from fractions import gcd


A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
print(
    B - B//C - B//D + B//lcm
    - ((A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm)
)
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

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

a, b, c, d = [int(_) for _ in input().split()]

e = int((c * d)/gcd(c, d))

a -= 1

ans = b -b//c - b//d + b//e
ans = ans - (a -a//c -a//d + a//e)

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

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

#count1=0
#count2=0
#for i in range(A,B+1):
#  if i%C!=0 and i%D!=0:
#    count+=1
#print(count)

e=B//C
f=B//D
g=(A-1)//C
h=(A-1)//D
i=e-g
j=f-h

P=gcd(C,D)
L=C*D//P
k=(A-1)//L
m=B//L
n=m-k

print(B-A+1-i-j+n)
def euclidian(a, b): #ユークリッドの互除法
    
    tmp = max(a,b)
    b = min(a,b)
    a = tmp

    mod = 1
    
    while (mod > 0):
        mod = a % b
        a, b = b, mod
    
    return(a)

low, high, C, D = map(int, input().split())

common = C * D // euclidian(C, D)
right_count = high - (high // C + high // D) + high // common 
l_tmp = low - 1
left_count = l_tmp - (l_tmp // C + l_tmp // D) + l_tmp // common

answer = right_count - left_count
print(int(answer))
from fractions import gcd


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


A, B, C, D = map(int, input().split())
SUM = B - A + 1
c = (B // C - (A - 1) // C)
d = (B // D - (A - 1) // D)
cd = (B // lcm(C, D) - (A - 1) // lcm(C, D))
print(SUM - (c + d - cd))