peterverebics/CodeNet_Python_118 huggingface dataset:
a,b,c,d=map(int, input().split())
def modz(x,y,z):
  if x%z==0:
    if y%z==0:
      return (y-x)//z+1
    else:
      return (y-x)//z+1
  else:
    if b%c==0:
      return (y-x)//z+1
    else:
      return y//z-x//z
if a//c or a//d:
  if b//c or b//d:
    ans=2
  else:
    ans=1
else:
  if b//c or b//d:
    ans=1
  else:
    ans=0
print(b-a-(modz(a-1,b,c)+modz(a-1,b,d)-modz(a-1,b,c*d))+ans)
a, b, c, d = map(int, input().split())

s1 = (a-1) // c
s2 = (a-1) // d
s3 = (a-1) // (c*d)
S = (a-1) - (s1 + s2 -s3)

l1 = b // c
l2 = b // d
l3 = b // (c*d)
L = b - (l1 + l2 - l3)

print(L-S)
import math
A,B,C,D=map(int,input().split())

nc=int((B+0.01)/C)-int((A-0.5)/C)
nd=int((B+0.01)/D)-int((A-0.5)/D)
gg=C*D/math.gcd(C,D)
ncd=int((B+0.01)/gg)-int((A-0.5)/gg)

print(B-A+1-nc-nd+ncd)
import math 
import fractions
a, b, c, d= map(int,input().split())
e = math.floor(b/c)-math.floor(a/c)
f = math.floor(b/d)-math.floor(a/d)
cd = c * d // fractions.gcd(c,d)
g = math.floor(b/cd)-math.floor(a/cd)
print(b-a+1-e-f+g)
from math import floor

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

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

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


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

CD = lcm(C,D)
CDdiff = floor(B/CD) - floor((A-1)/CD)



res = Cdiff+Ddiff-CDdiff
print((B-A+1)-res)
A,B,C,D = list(map(int, input().split()))
cd = (B - int(B/C)) - (A - int(A/C))

dd = (B - int(B/D)) - (A - int(A/D))
ed = (B - int(B/(C*D))) - (A - int(A/(C*D)))
print(cd+dd-ed)
li = list(map(int,input().split()))
countC = li[1] // li[2] - li[0] // li[2]
if li[0] % li[2] == 0:
  countC += 1

countD = li[1] // li[3] - li[0] // li[3]
if li[0] % li[3] == 0:
  countD += 1

countCD = li[1] // (li[2] * li[3]) - li[0] // (li[2] * li[3])
if li[0] % (li[2] * li[3]) == 0:
  countCD += 1

re = (li[1] - li[0] + 1) - (countC +countD - countCD)
print(re)
def ans(A, B, X):
  A = A - A % X + X
  if A > B:
    return 0
  else:
    return (B - A)//X + 1
A, B, C, D = map(int, input().split())
print(B - A + 1 - ans(A, B, C) - ans(A, B, D) + ans(A, B, C * D))
from fractions import gcd
A, B, C, D = map(int, input().split())
A -= 1
a = A - ((A//C)+(A//D)-(A//(C*D/gcd(C,D))))
b = B - ((B//C)+(B//D)-(B//(C*D/gcd(C,D))))
print(int(b - a))
a,b,c,d = map(int, input().split())
ans = b - a + 1
cntc = b//c - (a-1)//c
cntd = b//d - (a-1)//d
cntcd = b//(c*d) - (a-1)//(c*d)
ans = ans - cntc - cntd + cntcd
print(ans)
import fractions

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

# (B - A + 1) - n(C) - n(D) + n(C∩D)

def count_divisible_numbers(x):
  a = (A-1) // 2
  b = B // 2
  return b - a

n_C = count_divisible_numbers(C)
n_D = count_divisible_numbers(D)
CD_lcm = C*D // fractions.gcd(C, D)
n_CD = count_divisible_numbers(CD_lcm)

res = (B - A + 1) - n_C - n_D + n_CD
print(res)
import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
X=B-A; c=X//C; d=X//D; l=X//lcm(C,D)
print(X-c-d+l)
line = input().split()
import fractions
cd = int(int(line[2])*int(line[3]) / fractions.gcd(int(line[2]),int(line[3])))

total = int(line[1]) - int(line[0]) + 1

pos_c = int(int(line[1])/int(line[2])) - int((int(line[0])-1)/int(line[2]))
pos_d = int(int(line[1])/int(line[3])) - int((int(line[0])-1)/int(line[3]))
pos_cd = int(int(line[1])/cd) - int((int(line[0])-1)/cd)

answer = total - pos_c - pos_d + pos_cd

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


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

n=(b//c)-((a-1)//c)
m=(b//d)-((a-1)//d)
o=(b//e)-(a//e)



print(b-a+1-n-m+o)
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((b-a+1) - cPower - dPower + cdPower)
from fractions import gcd
a, b, c, d = map(int, input().split())
"""
ans: (B-A) - {Cの倍数の個数＋Dの倍数の個数 - lcm(C,D)の倍数の個数}
"""
def count(t):
    if a % t + (b-a+1)%t >= t:
        return (b-a+1)//t+1
    else:
        return (b-a+1)//t
    
cd = c * d // gcd(c, d)
print( b-a+1 - (count(c) + count(d) - count(cd)))
A, B, C, D = map(int, input().split())
def anti(A, B, m):
  ans = (B-A+1)//m
  mo = (B-A+1)%m
  if mo != 0 and mo >= A%m:
    ans += 1
  return ans

import fractions
g = fractions.gcd(C,D)
h = int((C*D)//g)
x = anti(A,B,C)
y = anti(A,B,D)
z = anti(A,B,h)
ans = B-A+1-x-y+z
print(ans)
A, B, C, D = map(int, input().split())
x = 0
for i in range(B-A):
  if (i+A)%C != 0 and (i+A)%D != 0:
    x += 1
  else:
    x += 0
print(x)
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)
    return n-e

print(main(b)-main(a-1))
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()))
a,b,c,d = iim()

def num(i):
    mulc = i//c
    muld = i//d
    mulcd = i//(c*d)
    return i-mulc-muld+mulcd

print(num(b)-num(a-1))
def div(n, m):
  return n // m
a, b, c, d = map(int, input().split())
ans = 0
a -= 1
e = b - div(b, c) - div(b, d)
f = a - div(a, c) - div(a, d)
x = c * d
if c < d:
  tmp = c
  c = d
  d = tmp
r = c % d
while r != 0:
  c = d
  d = r
  r = c % d
lcm = x/d
e += div(b, lcm)
f += div(a, lcm)
ans = int(e - f)
print(ans)
A,B,C,D=map(int,input().split())

all = B - A + 1
Cmod = B//C - (A-1)//C
Dmod = B//D - (A-1)//D
CDmod = B//(C*D) - (A-1)//(C*D)

print(all - Cmod - Dmod + CDmod)
import math

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

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

cnt = []

CD = int(C*D / gcd(C, D))

for i in [C, D, CD]:
    if i > B:
        cnt.append(0)
        continue
    first = math.ceil(A/i)*i
    if first > B:
        cnt.append(0)
        continue
    count = (B-first)//i + 1
    cnt.append(count)

ans = (B-A+1) - (cnt[0]+cnt[1]-cnt[2])

print(int(ans))
def gcd(x,y):
  while y:
    x,y = y,x%y
  return x

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


def main():
    a, b, c, d = map(int, input().split())
    cd = c * d // math.gcd(c, d)
    x = math.floor(b / c) - math.ceil(a / c) + 1
    y = math.floor(b / d) - math.ceil(a / d) + 1
    z = math.floor(b / cd) - math.ceil(a / cd) + 1
    print(b - a + 1 - x - y + z)


if __name__ == '__main__':
    main()
a,b,c,d = map(int,input().split())
h = a-b + 1
e = c*d
m = h//c + int(a%c==0)
k = h//d + int(a%d==0) 
l = h//e + int(a%e==0)
print(h-(m+k-l))
a,b,c,d=map(int,input().split())

def f(x):
  return x-(x+c-1)//c-(x+d-1)//d+(x+c*d-1)//(c*d)

ans=f(b)-f(a-1)

print(ans)
a, b, c, d=map(int, input().split())
counter=0
for x in range(a, b):
   if x % c > 0:
      if x % d > 0:
         counter=counter+1

print(counter)
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*b//gcd(a,b)
def main(a,b,c):
  if a%c==0 or b%c==0:
    s=(b-a)//c+1
  else:
    s=(b-a)//c
  return s
S=main(A,B,C)
T=main(A,B,D)
U=main(A,B,lcm(C,D))
V=S+T-U
print(B-A+1-V)
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

if (c == 1) or (d == 1):
    print(0)
    sys.exit()

c_all  = b//c
d_all  = b//d
cd_all = int(b//(c*d/gcd(c,d)))
count_all = b + cd_all - c_all - d_all

c_a  = (a-1)//c
d_a  = (a-1)//d
cd_a = int((a-1)//(c*d/gcd(c,d)))
count_a = a - 1 + cd_a - c_a - d_a

print(count_all - count_a)
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 = count
        else:
            count += 1
print(count)
a,b,c,d = map(int, input().split())
num = b-a+1
for i in range(a,b+1):
    if i%c == 0 and i%d == 0:
        num -= 1
print(num)
a,b,c,d=map(int,input().split())

def div(x):
  a_mod=a%x
  b_mod=b%x
  if b-a>x and b_mod>=a_mod and a_mod!=0:
    return (b-a)//x
  else:
    return (b-a)//x+1
  
print(b-a+1-div(c)-div(d)+div(c*d))
def main():
    import math
    a,b,c,d = map(int,input().split())
    al = b-a+1
    cdiv = b//c-math.ceil(a/c)+1
    ddiv = b//d-math.ceil(a/d)+1
    gcd = c*d//math.gcd(c,d)
    cddiv = b//gcd-math.ceil(a/gcd)+1
    print(al-cdiv-ddiv+cddiv)

if __name__ == "__main__":
    main()
a,b,c,d = map(int,input().split())
b += 1
a -= 1
ans = b-a
ans -= b//c - a//c
ans -= b//d - a//d
cd = c*d
ans += b//cd - a//cd
print(ans)
a,b,c,d = map(int, input().split())
e = 0
for l in range(a,b):
    if l%c != 0 and l%d != 0:
        e += 1
print(e)
#abc133 c
a,b,c,d=map(int,input().split())

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

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

e=lcm(c,d) #c,dの最小公倍数

def kosu(num):
    z=num
    nc=int(num/c)
    nd=int(num/d)
    ne=int(num/e)
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

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

def calc_kukan_num(mod):
    start = A if A % mod == 0 else A + mod - (A+mod) % mod
    return (B - start) // mod + 1
print(B-A+1-calc_kukan_num(C)-calc_kukan_num(D)+calc_kukan_num(C*D))
a,b,c,d=map(int,input().split())

def div(x):
  a_mod=a%x
  b_mod=b%x
  if a_mod<=b_mod and a_mod!=0:
    return (b-a)//x-1
  else:
    return (b-a)//x+1
  
print(b-a+1-div(c)-div(d)+div(c*d))
line = input().split()
import fractions
lcm = int(int(line[2])*int(line[3]) / fractions.gcd(int(line[2]),int(line[3])))

pos_c = int(int(line[1])/int(line[2])) 
pos_d = int(int(line[1])/int(line[3])) 
pos_lcm = int(int(line[1])/lcm)

pos_c1 = int((int(line[0])-1)/int(line[2])) 
pos_d1 = int((int(line[0])-1)/int(line[3])) 
pos_lcm1 = int((int(line[0])-1)/lcm)

b = int(line[1]) - pos_c - pos_d + pos_lcm
a = int(line[0]) - 1 - pos_c1 - pos_d1 + pos_lcm1

print(b-a)
import math

def getDivCount( a, b, x ):
    count=0
    if a==0 :
        count+=1
    count+=b//x-a//x
    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)
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 = math.floor(B/D)-math.floor((A-1)/D)
c_cnt = math.floor(B/C)-math.floor((A-1)/C)
cd = lcm(C,D)
cd_cnt = math.floor(B/cd)-math.floor((A-1)/cd)
print(B-A+1-(c_cnt+d_cnt-cd_cnt))
#C
import math
a, b, c, d = map(int, input().split())

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

s = b - a + 1
cc = b // c - (a - 1) // c
dd = b // d - (a - 1) // d
cd = b * a // gcd(a, b)
cd = b // cd + (a - 1) // cd
s -= cc + dd - cd
print(s)
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)
CC = int(B / C) - int((A - 1) / C)
DC = int(B / D) - int((A - 1) / D)
EC = int(B / E) - int((A - 1) / E)

print(B - A + 1 - CC - DC + EC)
import sys
import os
import fractions

MOD = 10 ** 9 + 7


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    E = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    ret += A // lcm(C, D)
    print(E - ret)


if __name__ == '__main__':
    main()
import math

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

s1=b//c - a//c
s2=b//d - a//d
s12=int( b//(c*d/math.gcd(c,d)) - a//(c*d/math.gcd(c,d)) )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))
a,b,c,d = map(int,input().split())
v,h = max(c,d),min(c,d)
while (v%h != 0):
    t = v
    u = h
    v = h
    h = t%u
lcm = max(c,d)*(int(min(c,d)/h))
r = 0
f = h
e = (b+1)-a
a -= 1
r += int(b/c)
r += int(b/d)
r -= int(b/lcm)
r -= int(a/c)
r -= int(a/d)
r += int(a/lcm)
print(e-r)
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+1)-res)
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))
a, b, c, d = list(map(int, input().split()))

c_b = int(b / c)
c_a = int((a-1)/c)
d_b = int(b/d)
d_a = int((a-1)/d)
cd_b =int(b / (c * d))
cd_a = int((a-1)/(c * d))

c_ans = c_b - c_a
d_ans = d_b - d_a
cd_ans = cd_b - cd_a
ans = c_ans + d_ans - cd_ans
print(b - a + 1 - ans)
import sys
input=sys.stdin.readline
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,B,C,D = map(int,input().split())
import fractions
e = fractions.gcd(C,D)
f = C * D / e
b = B// f
a = (A-1) // f
print(int(b-a))
import math

A,B,C,D = map(int, input().split())
a = B//C - A//C
b = B//D - A//D
lcm = C*D//math.gcd(C,D)
c = B//lcm - A//lcm
print(B-A-(a+b-c))
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)
from fractions import gcd
a, b, c, d = map(int, input().split())
n = b - a + 1
x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = int(b//((c*d)/gcd(c, d)) - (a-1)//((c*d)/gcd(c, d)))
print(n - (x + y - z))
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc131_c

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

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

def f(x, c, d):
    res = x
    res -= x // c 
    res -= x // d 
    res += x // lcm(c, d)
    return res

a, b, c, d = map(int, input().strip().split())
res = f(b, c, d) - f(a-1, c, d)

print(int(res))
import fractions
A, B, C, D = map(int, input().split())
cnt = 0
ac = (A-1) // C
bc = B // C
ad = (A-1) // D
bd = B // D
gcd_b = B // (C*D//fractions.gcd(C, D))
gcd_a = (A-1) // (C*D//fractions.gcd(C, D))
total = B - A + 1
a = bc - ac
b = bd - ad
gcdx = gcd_b - gcd_a
print(ac, bc, ad, bd, gcd_b, gcd_a)

print(total-a-b+gcdx)
import math
A,B,C,D = map(int,input().split())
count = 0
a = (B/C)-(A/C)
b = (B/D)-(A/D)
c = (B/(C*D))-(A/(C*D))

if a > 1:
  a = math.ceil(a)
else:
  a = 0
if b > 1:
  b = math.ceil(b)
else:
  b = 0
if c > 1:
  c = math.ceil(c)
else:
  c = 0
if A%C == 0 and B%C == 0:
  a += 1
if A%D == 0 and B%D == 0:
  b += 1
if A%(C*D) ==0 and B%(C*D) == 0:
  c += 1

ans = B-A+1 - (a+b-c)
print(ans)
import fractions

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)

cd = c*d // fractions.gcd(c,d)
print(cd)
import math
A,B,C,D = map(int, input().split())


t = C*D

 
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))
import math
a,b,c,d=map(int,input().split())
e=a*b//math.gcd(a,b)
if a%c==0:
  p=b//c-a//c+1
else:
  p=b//c-a//c
if a%d==0:
  q=b//d-a//d+1
else:
  q=b//d-a//d
if a%e==0:
  r=b//e-a//e+1
else:
  r=b//e-a//e
print(b-a+1-(p+q-r))
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))
X = A-B
Y = lcm(C,D)
i = B//C-(A-1)//C
j = B//D-(A-1)//D
k = B//Y-(A-1)//Y
print(Y)
print(int(B-A+1-(i+j-k)))
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)))
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)
import collections
import math
A,B,C,D=map(int,input().split())

nc=int(B/C)-int((A-1)/C)
nd=int(B/D)-int((A-1)/D)
gg=C*D/math.gcd(C,D)
ncd=int(B/gg)-int((A-1)/gg)

print(B-A+1-nc-nd+ncd)
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//c
ans_d = b//d - a//d
ans_r = b//g - a//g
print(r - ans_c - ans_d + ans_r)
x = input().split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

c_count = 0
d_count = 0
cd_count = 0

for i in range(a,b+1):
    if i % (c*d) == 0:
        cd_count += 1
    if i % c == 0:
        c_count += 1
    if i % d == 0:
        d_count += 1

print((b+1-a)-c_count-d_count+cd_count)
import sys
input = sys.stdin.readline
import fractions

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

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

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

    print(Bdec - Adec)


main()
import sys
from heapq import heappush, heappop
from fractions import gcd
#input = sys.stdin.readline

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

if __name__ == '__main__':
    main()
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))))
a,b,c,d=map(int,input().split())
q=[a,b+1]
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())
print(B-A+1-(((B//C)+(B//D)-(B//(C*D)))-((A//C)+(A//D)-(A//(C*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):
    if A % x:
        a = A + (x - A % x)
    else:
        a = A
    if B - a >= 0:
        return math.ceil((B - a + 1) / x)
    else:
        return 0
    
ans = (B - A + 1) - f(C) - f(D) + f(lcm_(C, D))
print(ans)
from fractions import gcd
a,b,c,d=map(int,input().split())
print(b-a+1-(b//c+b//d-b//gcd(c,d)+(a-1)//c+(a-1)//d-(a-1)//gcd(c,d)))
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:52:33 2020

@author: Kanaru Sato
"""

import fractions

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

a,b,c,d = list(map(int,input().split()))
cd = (c*d)/fractions.gcd(c,d)
ans = divnum(a,b,c) + divnum(a,b,d) - divnum(a,b,cd)
print(int(b-a+1-ans))
import sys
import math

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

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


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
d = abs(d)
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 = list(map(int, input().split()))
nans = 0
import math
cs = A if A % C == 0 else math.ceil(A / C) * C
ds = A if A % D == 0 else math.ceil(A / D) * D
E = (C * D) // math.gcd(C, D)
print(E)
es = A if A % E == 0 else math.ceil(A / E) * E

ce = B // C * C
de = B // D * D
ee = B // E * E

nans = (ce - cs) // C + 1 + (de - ds) // D + 1 - ((ee - es) // E + 1)
print(B - A + 1 - nans)
import math


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

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

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


if __name__ == "__main__":
    main()
A,B,C,D=map(int,input().split())
A-=1
print(B-A-(B//C+B//D-B//(C*D)-(A//C+A//D-A//(C*D))))
a,b,c,d = map(int, input().split())

c1, d1, cd1 = b // c, b // d, b // (c*d)
c2, d2, cd2 = (a-1) // c, (a-1) // d, a // (c*d)
ans = (c1+d1-cd1) - (c2+d2-cd2)
print((b-a+1) - ans)
def gcd(c, d):
  if c <= d:
    c, d = d, c
  while c % d:
    c, d = d, c % d
  return d
def lcm(c, d):
  return (c * d) // gcd(c, d)

A, B, C, D = map(int, input().split())
c_or_d = ((B // C) - (A // C)) + ((B // D) - (A // D)) - ((B // lcm(C, D)) - (A // lcm(C, D)))
print(B - A + 1 - c_or_d)
from fractions import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = (A - 1) // C, (A - 1) // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), (A - 1) // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
print(ans)
import math
import fractions

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

# (B - A + 1) - n(C) - n(D) + n(C∩D)

def count_divisible_numbers(x):
  a = math.ceil(A/x)
  b = math.floor(B/x)
  if a <= b:
    return b - a + 1
  else:
    return 0

n_C = count_divisible_numbers(C)
n_D = count_divisible_numbers(D)
CD_lcm = C*D // fractions.gcd(C, D)
n_CD = count_divisible_numbers(CD_lcm)

res = (B - A + 1) - n_C - n_D + n_CD
print(res)
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())
b += 1
A = a-((a//c) + (a//d) - a//lcm(c,d))
B = b-((b//c) + (b//d) - b//lcm(c,d))
print(B-A)
from fractions import gcd

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

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

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

print(answer)
import sys
import math

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

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())

if (B-(A+C-A%C))<0:
    cs=0
else:
    cs=(B-(A+C-A%C))//C+1
if (B-(A+D-A%D))<0:
    ds=0
else:
    ds=(B-(A+D-A%D))//D+1
if (B-(A+(C+D)-A%(C+D)))<0:
    cds=0
else:
    cds=(B-(A+C+D-A%(C+D)))//(C+D)+1


print(B-A-(cs+ds-cds))
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1
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)
A,B,C,D = map(int,input().split())
E = -(-(B-A)//C)-(-(B-A)//D)+(-(B-A)//(C*D))
print(B-A+1-E)
from fractions import gcd
a, b, c, d = map(int, input().split(' '))

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