peterverebics/CodeNet_Python_118 huggingface dataset:
from fractions import gcd
a,b,c,d = map(int, input().split())
ci = b//c - (a-1)//c
di = b//d - (a-1)//d
e = c * d // gcd(c, d)
cdi = b//e - (a-1)//e
print(b-(a-1)-(ci+di-cdi))
def wareru(x,y,z):
  if x%z == 0:
    return y//z - x//z + 1
  else:
    return y//z - x//z

import fractions

a,b,c,d = map(int,input().split())
e = c*d//(fractions.gcd(c,d))
c_hoge = wareru(a,b,c)
d_hoge = wareru(a,b,d)
e_hoge = wareru(a,b,e)
print(b-a+1-c_hoge-d_hoge+e_hoge)
A, B, C, D = map(int, input().split())
import fractions
g = fractions.gcd(C, D)
ac = (A-1)//C
bc = B//C
c = bc-ac
ad = (A-1)//D
bd = B//D
d = bd-ad
cdg = (C*D)//g
acd = (A-1)//cdg
bcd = B//cdg
cd = bcd-acd
ans = B-A+1-c-d+cd
print(ans)
import math
a, b, c, d = map(int, input().split())

s1 = (a-1) // c
s2 = (a-1) // d
s3 = (a-1) // (c*d//math.gcd(c,d))
S = (a-1) - (s1 + s2 -s3)

l1 = b // c
l2 = b // d
l3 = b // (c*d//math.gcd(c,d))
L = b - (l1 + l2 - l3)

print(L-S)
import fractions


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


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


def count_target(n):
    c_multiples = n // C
    d_multiples = n // D
    cd_multiples = n // lcm_cd
    return n - c_multiples - d_multiples + cd_multiples


count2a = count_target(A - 1)
count2b = count_target(B)

print(count2b - count2a)
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
A,B,C,D=map(int,input().split())
c=int(C*D/gcd(C,D))
b=int(B//C)+int(B//D)-int(B//c)
a=int((A-1)//C)+int((A-1)//D)-int((A-1)//c)
print(int((B-b)-(A-1-a)))
a,b,c,d = map(int,input().split())
all_val = b-a+1
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
if a%c == 0:
  c_val = b//c-a//c+1
else:
  c_val = b//c-a//c
if a%d == 0:
  d_val = b//d-a//d+1
else:
  d_val = b//d-a//d
if a%lcm(c,d) == 0:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)+1
else:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)
print(all_val-c_val-d_val+lcm_val)
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c,d=MI()
    cc=b//c - (a-1)//c
    dd=b//d - (a-1)//d
    
    import math
    g=(c*d)//math.gcd(c,d)
    gg=b//g - (a-1)//g
    
    print(b-a+1 -cc-dd+gg)

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

def anti_div(a,b,c):
    aa = (a-1) - (a-1) // c
    bb = b - b // c
    return bb - aa

# c,dの最小公倍数を求める
# l = c*d / gcd
#lcd = c // math.gcd(c,d) * d
lcd = c // fractions.gcd(c,d) * d

ans = anti_div(a,b,c) + anti_div(a,b,d) - anti_div(a,b,lcd)
print(ans)
A,B,C,D = map(int,input().split())
import math
E = C*D//math.gcd(C,D)
A -= 1
c = B//C - A//C
d = B//D - A//D
e = B//E - A//E
print(B-A-(c+d-e))
A, B, C, D = list(map(int, input().split()))
c1 = (A - 1) // C
c2 = B // C
d1 = (A - 1) // D
d2 = B //D
import math
E = (C * D) // math.gcd(C, D)
e1 = (A - 1) // E
e2 = B //E

print(B - A + 1 -(c2 - c1 + d2 - d1 - (e2 - e1)))
import math
A, B, C, D = map(int, input().split())
# 対象となる数の個数
num = B - A + 1
# Cで割り切れる数の個数
C_div = B // C - (A - 1) // C
# Dで割り切れる数の個数
D_div = B // D - (A - 1) // D
# CでもDでも割り切れる数の個数
CandD =  (C * D) // math.gcd(C, D)
CandD_div = B // CandD - (A - 1) // CandD
# CもしくはDで割り切れる数の個数
CorD_div = C_div + D_div - CandD_div
res = num - CorD_div
print(res)
import math

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

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

print((b- b//c - b//d + (b // lcm(c,d))) - ((a-1)- (a-1)//c - (a-1)//d +( (a-1) // lcm(c,d))))
import math

def Div(a,b,c):
  #a<=x<=bのうちcで割り切れるものの数を返す
  l = ((a-1)//c+1)*c
  r = (b//c)*c
  return (r-l)//c+1

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

print(B-A+1-(Div(A,B,C)+Div(A,B,D)-Div(A,B,C*D//math.gcd(C,D))))
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(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)
print((b-(b//c+b//d-b//lcm))-(a-1-((a-1)//d+(a-1)//c-(a-1)//lcm)))
import math
a,b,c,d=map(int, input().split())
def gcd(a,b):
    if(a%b!=0):
        return gcd(b,a%b)
    else:
        return b
def lcm(a,b):
    return a*b//gcd(a,b)

numb = b-(b//c + b//d) + (b//(lcm(c,d)))
numa = (a-1)-((a-1)//c+(a-1)//d) + ((a-1)//lcm(c,d))
print(numb-numa)
import fractions
a, b, c, d = list(map(int, input().split()))
ans = []
for n in [a - 1, b]:
    mc = n // c
    md = n // d
    cd = c * d // fractions.gcd(c, d)
    mcd = n // cd
    ans.append(n - mc - md + mcd)
print(int(ans[1] - ans[0]))
import sys
sys.setrecursionlimit(10**6)

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

#from math import gcd
from fractions import gcd

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

rem_ans = b//c - (a-1)//c + b//d - (a-1)//d - (b//f2 - (a-1)//f2)
ans = b-a+1-rem_ans
print(ans)
A, B, C, D = map(int, input().split())

def gcd(a,b):
    if b>a:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
E = lcm(C,D)

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

print(R)
import math
import fractions

A,B,C,D=map(int,input().split())
E=C*D//(fractions.gcd(C,D))
def P(A,B,Q):
	if A%Q==0:
		return B//Q-A//Q+1
	else:
		return B//Q-A//Q
print(B-A+1-(P(A,B,C))-(P(A,B,D))+(P(A,B,E)))
a, b, c, d = map(int, input().split())

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

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

l = lcm_base(c, d)

i = b//c-(a-1)//c
j = b//d-(a-1)//d
k = b//l-(a-1)//l
#print(i, j, k)
ans = b-a+1-(i+j-k)
print(ans)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

b_c = b - b // c
b_d = b - b // d
b_cd = b - b // lcm
z_to_b = b_c + b_d - b_cd

am1 = a-1
a_c = am1 - am1 // c
a_d = am1 - am1 // d
a_cd = am1 - am1 // lcm
z_to_a = a_c + a_d - a_cd

print(z_to_b - z_to_a)
from fractions import gcd

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

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

all_count = b - a + 1
c_count = b // c - (a-1) // c
d_count = b // d - (a-1) // d
cd_count = b // lcm - (a-1) // lcm

print(all_count - c_count - d_count + cd_count)
from fractions import gcd

a, b, c, d = map(int, input().split())
lcm = c * d // gcd(c, d)
x = b - (b // c) - (b // d) + (b // lcm)
y = (a - 1) - ((a - 1) // c) - ((a - 1) // d) + ((a - 1) // lcm)
print(x - y)
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)

print((b-a+1) - (p+q-r))
def resolve():
    A, B, C, D = map(int, input().split())
    d = D
    c = C
    gcd = 0
    while gcd == 0:
        if d % c == 0:
            gcd = c
        else:
            e = d%c
            d = c
            c = e
    lcm = C*D//gcd
    A = A-1
    print((B-B//C-B//D+B//lcm)-(A-A//C-A//D+A//lcm))
resolve()
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())
b_num = B//C + B//D - B//lcm(C,D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)

print((B-A+1) - (b_num - a_num))
import fractions
a,b,c,d=map(int,input().split())
before=(a-1)//c+(a-1)//d-(a-1)//(c*d//fractions.gcd(c,d))
after=b//c+b//d-b//(c*d//fractions.gcd(c,d))
print(before-after-a+b+1)
a, b, c, d = map(int, input().split())

p, q = c, d
while q:
  p, q = q, p % q
e = c * d // p

div_c = b // c - (a-1) // c
div_d = b // d - (a-1) // d
div_e = b // e - (a-1) // e

print(b - a + 1 - div_c - div_d + div_e)
import fractions
a,b,c,d = map(int,input().split())
def calc(n,x,y):
    cnt = n // x
    cnt += n//y
    lcm = x*y//fractions.gcd(x,y)
    cnt -= n//lcm
    return n - cnt

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

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x
lcm = c*d // gcd(c,d)

def cnt(z):
  return b//z - (a-1)//z

print(b+1-a-cnt(c)-cnt(d)+cnt(lcm))
# C
a,b,c,d = map(int,input().split())

import fractions

f=fractions.gcd(c,d)           #最大公約数
f2=c*d//f                          #最小公倍数

# a未満でcかdで割れるかず
a-=1
x = a//c
y = a//d
z = a//f2
ac = x+y-z

# b以下でcかdで割れるかず
x = b//c
y = b//d
z = b//f2
bc = x+y-z

print(b-a-(bc-ac))
from fractions import gcd

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

# 最小公倍数
lcm = (C * D) // gcd(C, D)

count = B
count -= B // C
count -= B // D
count += B // lcm
count -= (A - 1)
count += (A - 1) // C
count += (A - 1) // D
count -= (A - 1) // lcm

print(count)
import math
a,b,c,d=map(int,input().split())
n,m,k=0,0,0

if a%c==0:
    n=b//c-a//c+1
else:
    n=b//c-a//c
if a%d==0:
    m=b//d-a//d+1
else:
    m=b//d-a//d
e=(c*d)//math.gcd(c,d)
if a%e==0:
    k=b//e-a//e+1
else:
    k=b//e-a//e
k=n+m-k
print(b-a-k+1)
import fractions

def ceil(n, m):
    if n % m == 0:
        ans = n // m
    else:
        ans = (n + m) // m
    return ans

q = [0] * 3
nmul = [0] * 3

lower, upper, q[0], q[1] = [int(x) for x in input().split()]
q[2] = (q[0] * q[1]) // fractions.gcd(q[0], q[1])

for i in range(3):
    left = lower if (lower % q[i] == 0) else lower + q[i] - (lower % q[i])
    nmul[i] = ceil( upper - left + 1, q[i])

ans = upper - lower + 1 - nmul[0] - nmul[1] + nmul[2]

print(ans)
a, b, c, d = map(int, input().split())
from fractions import gcd
xc = (a-1)//c
yc = b//c
xd = (a-1)//d
yd = b//d    
xcd = (a - 1) // ((c * d) // gcd(c, d))
ycd = b // ((c * d) // gcd(c, d))

print(b - a + 1 -((yc - xc) + (yd - xd) - (ycd - xcd)))
a,b,c,d=map(int,input().split())
from math import gcd
ans=0
def main(n):
    e=n//c+n//d-n//((c*d)//gcd(c,d))
    return n-e

print(main(b)-main(a-1))
import numpy as np
A, B, C, D = map(int, input().split())

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

g = gcd(C, D)
l = (C*D)//g

x = B - ((B//C) + (B//D) - (B//l))
A = A-1
y = A - ((A//C) + (A//D) - (A//l))

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

#cで割り切れる数+dで割り切れる数-gcd(c,d)で割り切れる数を求めればよい
ans=(b//c+b//d-b//(c*d//math.gcd(c,d)))-((a-1)//c+(a-1)//d-(a-1)//(c*d//math.gcd(c,d)))

print(b-a+1-ans)
import math

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

C, D = c, d
if C < D:
  C, D = D, C
r = C % D
while r > 0:
  C = D
  D = r
  r = C % D
lcm = c * d // D

cPower = b//c - math.ceil(a/c) + 1
dPower = b//d - math.ceil(a/d) + 1
cdPower = b//lcm - math.ceil(a/lcm) + 1

print(max((b-a+1) - cPower - dPower + cdPower, 0))
import math
A, B, C, D = map(int, input().split())
L = C * D //math.gcd(C, D)
x = (A - 1) - (A -1) // C - (A - 1) // D + (A - 1) //L
y = B - B // C - B // D + B // L
print(y - x)
from fractions import gcd

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

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

c_num = b // c - (a - 1) // c
d_num = b // d - (a - 1) // d

c_d_lcm = c * d // gcd(c, d)
c_d_num = b // c_d_lcm - (a - 1) // c_d_lcm

ans = b - a + 1 - c_num - d_num + c_d_num
print(ans)
import sys
from math import pi

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    cDiv = (B // C) - ((A - 1) // C)
    dDiv = (B // D) - ((A - 1) // D)
    cd = C * D // gcd(C, D)
    cdDiv = (B // cd) - ((A - 1) // cd)
    print((B - A + 1) - (cDiv + dDiv - cdDiv))
    

    return 0

if __name__ == "__main__":
    solve()
import fractions
a,b,c,d = map(int,input().split())
AdivC = (a-1)//c
BdivC = b//c
AdivD = (a-1)//d
BdivD = b//d
gc = fractions.gcd(c,d)
div = (c*d)//gc
AdivCandD = (a-1)//div
BdivCandD = b//div

divC = BdivC - AdivC
divD = BdivD - AdivD
divCandD = BdivCandD - AdivCandD
ans = b-a+1
ans = ans -(divC+divD-divCandD)
print(ans)
def main():
    A, B, C, D = map(int, input().split())

    def lcm(v1, v2):
        v3 = v1 % v2
        if v3 == 0:
            return v2
        return lcm(v2, v3)

    def gcd(v1, v2):
        return v1 * v2 // lcm(v1, v2)

    count = B - (A - 1)

    c = B // C - (A - 1) // C
    d = B // D - (A - 1) // D

    CD = gcd(C, D)
    cd = B // CD - (A - 1) // CD

    print(count - c - d + cd)


main()
#!/usr/bin/env python3
def gcd(x, y):
    if x<y: x, y = y, x
    while y: x, y = y, x%y
    return x

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

a, b, c, d = map(int, input().split())
a -= 1
e = lcm(c, d)
print(b-a -b//c-b//d+b//e + a//c+a//d-a//e)
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))

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


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

def cnt(A, B, K):
    a = (A // K + (A % K != 0)) * K
    b = (B // K) * K
    if a > b:
        return 0
    else:
        return (b - a) // K + 1


lcm = c * d // gcd(c, d)
res1 = cnt(a, b, c)
res2 = cnt(a, b, d)
res3 = cnt(a, b, lcm)
print(b - a + 1 - res1 -res2 + res3)
import fractions
A,B,C,D=map(int,input().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
E=lcm(C,D)
a=A-1
ans=(a//C)+(a//D)-(a//E)
ans2=(B//C)+(B//D)-(B//E)
print(B-A+1-(ans2-ans))
from math import gcd
a,b,c,d=list(map(int,input().split()))
a-=1
def calculation(x,c,d):
	x=x-(x//c)-(x//d)+(x//((c*d)//gcd(c,d)))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
import fractions
a,b,c,d = iim()

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

from fractions import gcd
def f(n):
    #cとdの約数の個数をxに入れる
    x = n//c
    x += n//d
    #最小公倍数の約数を引く　例えば3,5であれば15の倍数を引く15,30,45...
    lcm = c*d // gcd(c,d)
    x -= n // lcm
    #どちらでも割れない
    return n-x

ans = f(b) - f(a-1)
print(ans)
from fractions import gcd
from math import ceil

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

def num(l,r,n):
    return r//n-(l-1)//n

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

l=lcm(c,d)
print((b-a+1)-num(a,b,c)-num(a,b,d)+num(a,b,l))
import fractions
a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
e=(c//g)*d
ans=(b//c-((a-1)//c))+(b//d-((a-1)//d))-(b//e-((a-1)//e))
print(b-a+1-ans)
import fractions

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

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

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

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

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

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

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

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)
import math

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

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)//lcm(c,d)
q4 = b//lcm(c,d)
print(b-(a-1) - (q21-q11) - (q22-q12) + (q4-q3))
# coding: utf-8
import math
a, b, c, d = map(int,input().split())

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

ans = b//c-(a-1)//c#cで
ans += b//d-(a-1)//d#dで
#print(ans)

ans -= b//e-(a-1)//e#両方で
print(int(b-a+1-ans))
import fractions
a,b,c,d = map(int, input().split())

x = (c*d)//fractions.gcd(c,d)
A = (a-1) - (a-1)//c - (a-1)//d + (a-1)//x
B = b - b//c - b//d + b//x
print(int(B-A))
#!/usr/bin/env python3

from fractions import gcd

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


def calc(min_, max_, div_num):
    if (min_ % div_num) != 0:
        min_ = min_ - (min_ % div_num)+div_num

    if min_ > max_:
        return 0
    return (max_-min_)//div_num+1


# print(calc(a, b, c))
# print(calc(a, b, d))
# print(calc(a, b, c*d//gcd(c, d)))
print((b-a+1)-(calc(a, b, c)+calc(a, b, d)-calc(a, b, c*d//gcd(c, d))))
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

A,B,C,D=MI()
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)
# solution
import io
import fractions

n, m, k, j = map(int, input().split())
n = n-1
data = int(k*j/fractions.gcd(k, j))
result = (m-m//k-m//j+m//data)-(n-n//k-n//j+n//data)
print(result)
import fractions
a,b,c,d=map(int,input().split())
bc=b//c
ac=(a-1)//c
bd=b//d
ad=(a-1)//d
bcd=b//((c*d)//fractions.gcd(c,d))
acd=(a-1)//((c*d)//fractions.gcd(c,d))
r=b-a+1
print(r-((bc-ac)+(bd-ad)-(bcd-acd)))
a,b,c,d = map(int, input().split())

from math import gcd

def calc(a, b, n):
    return b//n - (a//n+bool(a%n))

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

ac=(A-1)//C
ad=(A-1)//D
bc=B//C
bd=B//D
ae=(A-1)//E
be=B//E

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

print(B-A+1 - s -t +u)
A,B,C,D=map(int,input().split())
def f(x):
  return B//x-(A-1)//x
import math
E=int(C*D/math.gcd(C,D))
print(B-A+1-f(C)-f(D)+f(E))
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 - 1) // (c * d // gcd(c, d)))
from fractions import gcd
a, b, c, d = map(int, input().split())
def f(x):
	return x - x//c - x//d + x * gcd(c, d) // (c * d)
print(f(b) - f(a-1))
import fractions
A,B,C,D = list(map(int,input().split()))
gcd = fractions.gcd(C,D)
lcm = C*D//gcd
a = ((A-1)//C+(A-1)//D-(A-1)//lcm)
b = B//C+B//D-B//lcm
print(B-A+1-(b-a))
a,b,c,d = list(map(int, input().split()))

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

e = int(c*d/gcd(c,d))
cde = [c,d,e]

cde1 = []
for i in cde:
    a0 = 0 if a%i != 0 else 1
    a1 = b//i - a//i + a0
    cde1.append(a1)

x,y,z = cde1
print((b-a+1) - x - y + z )
#python3
from fractions import gcd

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


def main():
    a, b, c, d = map(int, input().split())
    p = b - ((b//c + b//d) - b//lcm(c, d))
    q = (a-1) - (((a-1)//c + (a-1)//d) - (a-1)//lcm(c, d))
    print(p-q)
main()
A,B,C,D = [int(x) for x in input().split()]
def gdc(x,y):
  if x%y == 0:
    return y
  else:
    return gdc(y,x%y)
g = C*D//gdc(D,C)
count= B-A+1-B//C+(A-1)//C-B//D+(A-1)//D+B//g-(A-1)//g
print(count)
import math

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

ans_lt_b = b - (b // c + b // d - b // lcm_cd)
ans_lt_a = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm_cd)
print(ans_lt_b - ans_lt_a)
def main():
    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 ans(N,C,D):
        return N-N//C-N//D+N//lcm(C,D)

    A,B,C,D = map(int,input().split())
    print(ans(B,C,D)-ans(A-1,C,D))
    
if __name__=="__main__":
    main()
import math
a,b,c,d=map(int,input().split())
cd = c*d // math.gcd(c,d)
# b以下のc,d,cdの倍数の個数からa未満のc,d,cdの倍数個数をそれぞれ引く
s_c = b//c - (a-1)//c
s_d = b//d - (a-1)//d
s_cd = b//cd - (a-1)//cd
print((b-a+1)-s_c-s_d+s_cd)
import fractions
    
a,b,c,d = map(int,input().split())
cd = c*d//fractions.gcd(c, d)

c1 = b//c
d1 = b//d
cd1 = b//(cd)

c2 = (a-1)//c
d2 = (a-1)//d
cd2 = (a-1)//cd

c3 = c1-c2
d3 = d1-d2
cd3 = cd1-cd2

print(b-a+1-c3-d3+cd3)
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    A, B, C, D = mi()
    A -= 1
    CD_lcm = C * D // math.gcd(C, D)
    ans = B - B//C - B//D + B//CD_lcm
    ans -= A - A//C - A//D + A//CD_lcm
    print(ans)
    return

main()
a,b,c,d=map(int,input().split())
lcm=0
cc=min(c,d)
dd=max(c,d)

while cc>0:
  amari=dd%cc
  dd=cc
  cc=amari

lcm=c*d//dd
  
bika=b-b//c-b//d+b//lcm
amiman=a-1-(a-1)//c-(a-1)//d+(a-1)//lcm
print(bika-amiman)
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(b-a+1-cnt2+cnt1)
a,b,c,d = map(int,input().split(" "))
ans = 0
from fractions import gcd
def lcm(x, y):
  return (x * y) // gcd(x, y)
a -= 1
f = lcm(c,d)
ans = (b - a) - ((b//c - a//c) + (b//d - a//d) - (b//f - a//f))

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

l = int(fractions.gcd(c,d) * c / fractions.gcd(c,d) * d / fractions.gcd(c,d))
#print(l)
x = b // c - a // c
y = b // d - a // d
z = b // l - a // l
if a % c == 0 or a % d == 0:
    print(int(b-a-(x+y-z)))
else:
    print(int(b-a-(x+y-z))+1)
#print(x,y,z)
A, B, C, D = map(int,input().split())
import fractions
lcm = C*D//fractions.gcd(C,D)
print((B-B//C-B//D+ B//lcm)-((A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm))
from fractions import gcd
A, B, C, D = map(int, input().split())
E = int(C * D / gcd(C, D))
def f(x):
  return (x - x // C - x // D + x // E)
print(f(B) - f(A-1))
import math
A,B,C,D=list(map(int,input().split()))
E=int(C * D / math.gcd(C, D))
print(((((B-A)+1)-((B//C)-((A-1)//C)))-((B//D)-((A-1)//D)))+(B//E)-((A-1)//E))
import sys
import math

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 = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
if c == d:
  fgh = (b // c) - ((a - 1) // c)
  n = e - fgh
  print(n) 
else:
  f = (b // c) - ((a - 1) // c)
  g = (b // d) - ((a - 1) // d)
  cd = lcm(c, d) 
  h = (b // cd) - ((a - 1) // cd)
  n = e - f - g + h
  print(n)
a, b, c, d = map(int, input().split())
import numpy as np
cmin = (a - 1) // c + 1
cmax = b // c
dmin = (a - 1) // d + 1
dmax = b // d
lcmcd = np.lcm(c, d)
cdmin = (a - 1) // lcmcd + 1
cdmax = b // lcmcd
csum = cmax - cmin + 1
dsum = dmax - dmin + 1
cdsum = cdmax - cdmin + 1
print((b - a + 1) - (csum + dsum - cdsum))
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
A,B,C,D = map(int,input().split())
a = gcd(C,D)
E = (C//a)*D
n1 = B//C
n2 = B//D
n3 = B//E
n = B-(n1+n2-n3)
m1 = (A-1)//C
m2 = (A-1)//D
m3 = (A-1)//E
m = A-1-(m1+m2-m3)
print(n-m)
from fractions import gcd
a, b, c, d = map(int, input().split(' '))

# cye bolunenler
c_numbers = b//c - (a-1)//c
# dye bolunenler
d_numbers = b//d - (a-1)//d
# ortak bolunenler
gcd_number = c*d // gcd(c, d)
ortak = b//(gcd_number) - (a-1)//(gcd_number)
# result
print(b-a+1-(c_numbers+d_numbers-ortak))
a, b, c, d = map(int, input().split())


x = b // c
y = b // d


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


z = b // e

x2 = (a-1) // c
y2 = (a-1) // d


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


z2 = (a-1) // e2


print((b - (x + y - z)) - (a - 1 - (x2 + y2 - z2)))
from fractions import gcd
A, B, C, D = list(map(int, input().split()))
num_B_C = B // C
num_B_D = B // D
lcm_C_D = int(C * D / gcd(C, D))
num_B = B - (num_B_C + num_B_D) + B // lcm_C_D

num_A_C = (A-1) // C
num_A_D = (A-1) // D
num_A = (A-1) - (num_A_C + num_A_D) + (A-1) // lcm_C_D

ans = num_B - num_A
print(ans)
import math

def getDivCount( a, b, x ):
    count=0
    if a!=0 :
        count+=b//x-(a-1)//x
    else:
        count+=b//x+1
    return count

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

count = b-a+1
count -= getDivCount(a,b,c)
count -= getDivCount(a,b,d)
count += getDivCount(a,b,c*d//math.gcd(c,d))
print(count)
from fractions import gcd

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

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

c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
CD = lcm(C, D)
cd = B // CD - (A - 1) // CD

ans = (B - A + 1) - (c + d - cd)
print(ans)
import math
A, B, C, D = map(int, input().split())
calc = lambda x: B//x-(A-1)//x
print((B-A+1)-calc(C)-calc(D)+calc(C*D//math.gcd(C, D)))