peterverebics/CodeNet_Python_118 huggingface dataset:
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

a,b,c,d = map(int,input().split())
lcm = (c*d) // gcd(c, d)
ans = b - a + 1
cdiv = b // c - (a-1) // c
ddiv = b // d - (a-1) // d
cddiv = b // lcm - (a-1) // lcm
#print(ans, cdiv, ddiv, cddiv, lcm)
ans -= cdiv + ddiv - cddiv
print(ans)
from fractions import gcd  # for python 3.5, use math.gcd


def main():
    A, B, C, D = list(map(int, input().split(' ')))
    gcd_cd = gcd(C, D)
    lcm_cd = C * D // gcd_cd
    A -= 1
    a = A - A // C - A // D + A // lcm_cd
    b = B - B // C - B // D + B // lcm_cd
    print(b - a)


if __name__ == '__main__':
    main()
import math
from decimal import Decimal
#from decimal import Decimal
a, b, c, d = map(Decimal, input().split())

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

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/((c*d)/gcd(c, d)))
    return tmp_a

print(int(count(b,c,d))-int(count(a-1, c, d)))
import math
import fractions

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

A,B,C,D=map(int,input().split())
E=B-A+1
F=B//C-(A-1)//C
G=B//D-(A-1)//D
H=B//lcm(C,D)-(A-1)//lcm(C,D)
count=E-F-G+H
print(count)
def solve():
    A, B, C, D = map(int, input().split())
    ans = B-A+1
    gcd_CD = gcd(C, D)
    CD = (C//gcd_CD)*(D//gcd_CD)*gcd_CD
    ans -= (B//C-(A-1)//C)
    ans -= (B//D-(A-1)//D)
    ans += (B//CD-(A-1)//CD)
    print(ans)


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


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

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

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

def counter(division):
    a = A // division
    if A % division == 0:
        a -= 1
    b = B // division
    return b - a

c = counter(C)
d = counter(D)
cd = counter(lcm(C , D))
ret = B - A + 1 - c - d + cd
print(ret)
a, b, c, d = map(int, input().split())
cc, dd, e = c, d, 1
for i in range(2, int(min(cc, dd)**0.5) + 1):
    if cc%i == 0 and dd%i == 0:
        while cc%i == 0 and dd%i == 0:
            cc //= i
            dd //= i
            e *= i
e *= cc*dd
print(b-a+1 - b//c + (a-1)//c - b//d + (a-1)//d + b//e - (a-1)//e)
def gcd(a,b):
  if b!=0:
    return gcd(b, a%b)
  else:
    return a
  
def lcm(a,b):
  return a//gcd(a,b)*b
  
def f(x, c, d):
  a = x
  a -= x//c
  a -= x//d
  a += x//lcm(c,d)
  return a
  
A,B,C,D = list(map(int, input().split()))

out = f(B, C, D) - f(A-1, C, D)
print(out)
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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


a, b, c, d = [int(_) for _ in input().split()]
print(b - a + 1 - ((b // c - (a-1) // c) + (b // d - (a-1) // d) - (b // lcm(c, d) - (a-1) // lcm(c, d))))
from math import gcd

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

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

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

X=f(B,C)-f(A-1,C)
Y=f(B,D)-f(A-1,D)
Z=f(B,E)-f(A-1,E)
print(B-A+1-(X+Y-Z))
from math import gcd
a,b,c,d=map(int,input().split())
def lcm(x,y):return x*y//gcd(x,y)
def f(x):
  return x-x//c-x//d+x//lcm(c,d)
print(f(b)-f(a-1))
def lcm(x,y):
    return x*y//gcd(x,y)

def cnt(x):
    return B//x - A//x + (A%x==0)

from math import gcd

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

print((B-A+1)-cnt(C)-cnt(D)+cnt(l))
from math import gcd, ceil
a, b, c, d = map(int, input().split())

def f(s, x, y):
    lcm = x * y // gcd(x, y)
    ret = s // x + s // y - s // lcm
    return ret

print(b-a+1-f(b, c, d)+f(a-1, c, d))
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt
from copy import deepcopy
from fractions import gcd

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

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


def main():
    A, B, C, D = [int(x) for x in input().split()]
    l = (C * D) // gcd(C, D)
    b = B - anti(B, C, D, l)
    a = (A - 1) - anti((A - 1), C, D, l)
    print(int(b - a))


def anti(x, y, z, l):
    return (x // y) + (x // z) - (x // l)


if __name__ == "__main__":
    main()
import math
a, b, c, d = map(int, input().split())


def calc(x):
    global c, d
    l = c // math.gcd(c, d) * d
    return x - x // c - x // d + x // l


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

C = b//c - (a-1)//c
D = b//d - (a-1)//d
x = c*d//math.gcd(c,d)
CD = b//x - (a-1)//x

print((b-a+1) - (C+D-CD))
import fractions

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

a, b, c, d = map(int,input().split())
ans = 0
a = a-1
 
x = b - (b//c + b//d - b//lcm(c,d)) #1~bまでの該当する数
y = a - (a//c + a//d - a//lcm(c,d)) #1~a-1までの該当する数
    
print(x-y)
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-1)//e)



print(b-a+1-n-m+o)
from fractions import gcd
def func(n):
    return n - (n//C + n//D - n//(C*D//gcd(C, D)))
A, B, C, D = map(int, input().split())
print(func(B) - func(A-1))
import sys
from math import ceil
from fractions import gcd

a, b, c, d = map(int, input().split())
if c == 1:
  print(0)
  sys.exit()
cd_lcm = c*d//gcd(c, d)
c_left, c_right = ceil(a/c), b//c
d_left, d_right = ceil(a/d), b//d
cd_left, cd_right = ceil(a/cd_lcm), b//(cd_lcm)
cv, dv, cdv = c_right - c_left + 1, d_right - d_left + 1, cd_right - cd_left + 1
print((b - a + 1) - (cv + dv - cdv))
#from math import gcd
from fractions import gcd
def lcm(s,t):
    return s*t//gcd(s,t)
def not_div(b,c,d):
    return b-(b//c + b//d - b//lcm(c,d))
a,b,c,d = map(int,input().split())
print(not_div(b,c,d)-not_div(a-1,c,d))
A,B,C,D = map(int,input().split())

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

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

p = B//C - (A-1)//C
q = B//D - (A-1)//D
r = B//l - (A-1)//l
s = p + q - r
print(B-A+1-s)
from fractions import gcd
a,b,c,d = map(int,input().split())
e = int(c*d/gcd(c,d))
n1 = b//c-a//c if a%c != 0 else b//c-a//c+1
n2 = b//d-a//d if a%d != 0 else b//d-a//d+1
n3 = b//e-a//e if a%e != 0 else b//e-a//e+1
print(b-a+1-n1-n2+n3)
from fractions import gcd
a,b,c,d = map(int, input().split())
 
lcm = (c*d)//gcd(c,d)
 
x = ((a-1)//c)+((a-1)//d)-((a-1)//lcm)
y = (b//c)+(b//d)-(b//lcm)
 
print((b-(a-1))-(y-x))
a,b,c,d=map(int,input().split())

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

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

def slice(n,c,d):
    ans=n
    ans-=(n//c)
    ans-=(n//d)
    ans+=(n//lcb(c,d))
    return ans

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

def main():
    A, B, C, D = map(int, input().split())
    nC = B//C - (A-1)//C
    nD = B//D - (A-1)//D
    CD = (C*D)//gcd(C, D)
    nCD = B//CD - (A-1)//CD
    cnt = nC + nD - nCD
    ans = B - A + 1 - cnt
    print(ans)

if __name__ == "__main__":
    main()
a, b, c, d = map(int, input().split())

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

def count(b, c, d):
    return b - b//c - b//d + b//(c * d // gcd(c, d))

print(count(b, c, d) - count(a-1, c, d))
import math 
import fractions
a, b, c, d= map(int,input().split())
e = b//c-(a-1)//c
f = b//d-(a-1)//d
cd = c * d // fractions.gcd(c,d)
g = b//cd -(a-1)//cd
print(b-a-e-f+g+1)
import fractions
A, B, C, D = map(int, input().split())
M = C * D // fractions.gcd(C, D)
def f(x):
  N = x - x//C - x//D + x//M 
  return N
print(f(B) - f(A-1))
import math
A, B, C, D = map(int, input().split())
total = B-A+1
A -= 1
waruC = (B//C)-(A//C)
waruD = (B//D)-(A//D)
CD = C * D // math.gcd(C, D)
waruCD = (B//CD)-(A//CD)
print(total-waruC-waruD+waruCD)
from math import gcd

a, b, c, d = map(int, input().split())
e = c // gcd(c, d) * d
cnt = lambda n: n // c + n // d - n // e
print(b - a + 1 - cnt(b) + cnt(a - 1))
from fractions import gcd
a,b,c,d = map(int,input().split())

cd = c * d // gcd(c, d)
ans = b - a + 1 - ((b // c - (a - 1) // c) + (b // d - (a - 1) // d) - (b // cd - (a - 1) // cd))
print(ans)
from fractions import gcd

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

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

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

print(numB - numA)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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


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


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

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

    print(B - A + 1 - (b - a))


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


def gcd(x, y):
    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())
ALL = b - a +1
G = lcm(c, d)
num = math.floor(b // c) - math.floor((a-1) // c) + math.floor(b // d) - math.floor((a-1) // d) - (math.floor(b // G) - math.floor((a-1) // G))
print(ALL - num)
import math
A, B, C, D = map(int, input().split())
CD = C * D // math.gcd(C, D)
ab = B - A + 1
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // (CD) - (A - 1) // (CD)

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

ans=B-A+1
ans-=B//C-(A-1)//C
ans-=B//D-(A-1)//D
E=lcm(C,D)
ans+=B//E-(A-1)//E
print(ans)
def common_multiple(x, y):
    for i in range(2, min(x, y)+1):
        x0, y0 = x % i, y % i
        if x0 == 0 or y0 == 0:
            return common_multiple(x // i if x0 == 0 else x, y // i if y0 == 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)
a,b,c,d = map(int, raw_input().split(' '))

def gcd(a,b):
	#a = bk + r
	if b == 0: return a
	return gcd(b, a % b)

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

# how many multiples of c among integers between a and b inclusive
def f(a,b,c):
	if a == 0:
		return b/c + 1
	return b/c  - (a-1)/c 

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

c1 = (B//C)-((A+C-1)//C)+1
c2 = (B//D)-((A+D-1)//D)+1
c3 = (B//E)-((A+E-1)//E)+1
ans = B-A+1-c1-c2+c3

print(ans)
a,b,c,d=map(int,input().split())
from fractions import gcd
def lcm(x,y):
  return x * y // gcd(x,y)

cZ = (b//c)-((a-1)//c)

dZ = (b//d)-((a-1)//d)

cdZ = (b//(lcm(c,d)))-((a-1)//(lcm(c,d)))

ans = b-a+1-cZ-dZ+cdZ
print(ans)
import math
a, b, c, d = map(int, input().split())
ac = (a - 1) // c
bc = b // c
ad = (a - 1) // d
bd = b // d
lcm = c * d // math.gcd(c,d)
acd = (a - 1) // lcm
bcd = b // lcm
print((b-a+1)-((bc-ac)+(bd-ad)-(bcd-acd)))
a,b,c,d = map(int,input().split())

import math

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

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

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

print(ans)
from math import gcd
def calc(a,b,n):
  return b//n-(a-1)//n
def solve():
  A, B, C, D = map(int, input().split())
  ans = B-A+1-calc(A,B,C)-calc(A,B,D)+calc(A,B,C*D//gcd(C,D))
  return ans
print(solve())
A,B,C,D=map(int,input().split())
a=B//C-(A-1)//C
b=B//D-(A-1)//D
def lcm(x,y):
    return x*y//gcd(x,y)

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

z=lcm(C,D)
c=B//z-(A-1)//z
print(B-A+1-a-b+c)
from fractions import gcd
a, b, c, d = list(map(int, input().split()))
#b = list(map(int, input().split()))
total = b-a+1
lcm = int((c*d)/gcd(c, d))

d1 = b//c - a//c
d2 = b//d - a//d
add = b//lcm - a//lcm
if a % c == 0:
    d1 += 1
if a % d == 0:
    d2 += 1
if a % lcm == 0:
    add += 1

print(total-d1-d2+add)
from fractions import gcd
a, b, c, d = map(int, input().split())

#c,d,lcm(c,d)の倍数がa~bの区間にいくつあるか調べる関数
def check(p):
    if a%p==0:
        e = a//p
    else:
        e = (a//p) +1

    if b%p==0:
        f = b//p
    else:
        f = (b//p)
        
    return(f-e+1)
        

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

divc = b//c-(a-1)//c
divd = b//d-(a-1)//d
import math
l = c*d//math.gcd(c,d)
divl = b//l-(a-1)//l
print(b-a+1-divc-divd+divl)
import fractions
def lcm(a,b):
    return a * b // fractions.gcd(a, b)

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


m1 = (a-1)//c
m2 = (a-1)//d
m3 = b//c
m4 = b//d


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

m5 = c*d//gcd(max(c,d),min(c,d))

m6 = (a-1)//m5
m7 = b//m5

ans = (b-a+1)-((m3-m1)+(m4-m2)-(m7-m6))
print(ans)
from fractions import gcd
a, b, c, d = map(int, input().split())

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

a_under = a-1

ans = (b - b//c - b//d + b//p) - (a_under - a_under//c - a_under//d + a_under//p)

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

from math import gcd
def cnt(n):
    lcm = c//gcd(c,d)*d
    return n - n//c - n//d + n//lcm
print(cnt(b)-cnt(a-1))
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import fractions

a,b,c,d = mi()

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

# cの倍数の個数
ac = (a-1)//c
bc = b//c
nc = bc-ac

# dの倍数の個数
ad = (a-1)//d
bd = b//d
nd = bd-ad

# cdのgcdの倍数の個数
ag = (a-1)//g
bg = b//g
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(ans)
from math import gcd


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


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


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

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

n=b-a+1

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

cc=b//c-(a-1)//c
dc=b//d-(a-1)//d
xc=b//x-(a-1)//x

print(n-cc-dc+xc)
from fractions import gcd
def lcm(x,y):
	return x*y//gcd(x,y)

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

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

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

A = b - (b//c + b//d -  b//e)
B = a - (a//c + a//d - a//e)
print(A-B)
import fractions
a,b,c,d=map(int,input().split())
cdgcd=(c*d)//fractions.gcd(c,d)
print(b-(a-1)-(b//c) +((a-1)//c) -(b//d) +((a-1)//d) +(b//cdgcd) -(a-1)//cdgcd)
from math import ceil, floor
from fractions import gcd

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

def div_count(n, p, q):
  lcm = p*q // gcd(p, q)
  return n - n//p - n//q + n//lcm

print(div_count(B, C, D) - div_count(A-1, C, D))
from math import gcd
#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)

a, b, c, d = map(int, input().split())
a -= 1
tmp1 = b - (b//c + b//d - b//(lcm(c, d)))
tmp2 = a - (a//c + a//d - a//(lcm(c, d)))

print(tmp1-tmp2)
A,B,C,D = list(map(int,input().split()))
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
x = max(C,D)
y = min(C,D)

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

L = (C*D)//gcd(x,y)
Z = B//L - (A-1)//L
  
print(B-A+1-X-Y+Z)
import math
a,b,c,d=map(int,input().split())
lcm_cd=c*d//math.gcd(c,d)
c_cnt=b//c-(a-1)//c
d_cnt=b//d-(a-1)//d
cd_cnt=b//lcm_cd-(a-1)//lcm_cd
print(b-a+1-c_cnt-d_cnt+cd_cnt)
import math
A,B,C,D = map(int,input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

E = B//C + (-A//C) + 1
F = B//D + (-A//D) + 1
G = B//lcm(C,D) + (-A//lcm(C,D)) + 1
H = E + F - G
print(B - A + 1 - H)
from math import gcd

def count(x, c, d):
  # x以下のcでもdでも割り切れない奴を数える
  lcm = c // gcd(c, d) * d
  return x - x // c - x // d + x // lcm

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

a,b,c,d = map(int,input().split())
a -= 1
def div(m,n):
	return m // n

ans_a = a - div(a,c) - div(a,d) + div(a,c*d//gcd(c,d))
ans_b = b - div(b,c) - div(b,d) + div(b,c*d//gcd(c,d))

print(ans_b - ans_a)
import fractions

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

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

multiple_C_under_A = (A - 1) // C
multiple_D_under_A = (A - 1) // D
multiple_CD_under_A = (A - 1) // lcm

multiple_C_under_B = B // C
multiple_D_under_B = B // D
multiple_CD_under_B = B // lcm

total = B - A + 1

print(total - (multiple_C_under_B - multiple_C_under_A + multiple_D_under_B - multiple_D_under_A - (
            multiple_CD_under_B - multiple_CD_under_A)))
import math
a,b,c,d = map(int,input().split())

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

print(int(ans_b-ans_a))
from math import gcd
lcm = lambda x,y: (x*y)//gcd(x,y)
A,B,C,D = [int(i) for i in input().split()]
print(B - A + 1 - (B//C - (A-1)//C) - (B//D - (A-1)//D) + (B//lcm(C,D) - (A-1)//lcm(C,D)))
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) // x
  b = B // x
  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 math

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

x=(a-1)//c

y=b//c
z=(a-1)//d
w=b//d

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

p=(a-1)//e

q=b//e

print(b-a+1-y+x-w+z+q-p)
import math
a,b,c,d=map(int,input().split())
e=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 math
a,b,c,d = map(int,input().split())
g = c*d//math.gcd(c,d)
print(b-a+1-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//g-(a-1)//g)))
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())

num_all = b - a + 1
num_c = (b // c) - (a // c)
if a % c == 0:
    num_c += 1
num_d = (b // d) - (a // d)
if a % d == 0:
    num_d += 1
lcm_cd = lcm(c, d)
num_cd = (b // lcm_cd) - (a // lcm_cd)
if a % lcm_cd == 0:
    num_cd += 1

print(num_all - num_c - num_d + num_cd)
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
A,B,C,D = map(int,input().split())
c1 = B//C-(A-1)//C
d1 = B//D-(A-1)//D
E = (C//gcd(C,D))*D
e1 = B//E-(A-1)//E
print(B-A+1-c1-d1+e1)
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)

#Bで割り切れれない数 = B - Bで割り切れる数
_not_Divisible_number_B = B - (B//C + B//D - B//lcm(C,D))

#A以上B以下なので
lowA =  A -1

_not_Divisible_number_A_1 = lowA - (lowA//C + lowA//D - lowA//lcm(C,D))

ans = _not_Divisible_number_B - _not_Divisible_number_A_1

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

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

f = (b//c + b//d) - b//e
g = ((a-1)//c + (a-1)//d) - (a-1)//e
print (b-a+1-(f-g))
def sumcnt(a, b, val):
  am=(a-1)//val
  bm=b//val
  return bm-am

a,b,c,d=map(int,input().split())
p=c
q=d
while p%q>=1:
  bk=p%q
  p=q
  q=bk
mc=c//q
md=d//q
m=mc*md*q
summ=sumcnt(a,b,m)
sumc=sumcnt(a,b,c)
sumd=sumcnt(a,b,d)
print((b-a+1)-(sumc+sumd-summ))
a,b,c,d = map(int,input().split())
from fractions import gcd
a -= 1
nya = c//gcd(c,d) * d # 最小公倍数
# オイラー関数
ca = a//c
da = a//d
#print(ca,da)
cda = ca + da - a//nya
ans_a = a - cda
cb = b//c
db = b//d
#print("cddb",cb,db)
cdb = cb + db - b//nya
ans_b = b - cdb
print(ans_b - ans_a)
#print(ans_a,ans_b)
#print(nya)
#ans = ans_b - ans_a
#print(ans)
import math
a, b, c, d = map(int, input().split())

c_f = (a + c - 1) // c
c_e =  b // c
d_f = (a + d - 1) // d
d_e =  b // d

cd = c * d // math.gcd(c, d)
c_d_num = b // cd - (a + cd - 1) // cd + 1

num = b - a + 1 - (c_e - c_f + 1 + d_e - d_f + 1 - c_d_num)
 
print(num)
from math import gcd
A, B, C, D = map(int, input().split())
E = C*D//gcd(C, D)
ans = B-A+1 - (B//C-(A-1)//C + B//D-(A-1)//D - B//E+(A-1)//E)
print(ans)
import math
a, b, c, d = map(int, input().split())
e = b - ((b // c) + (b // d) - (b // (c * d // math.gcd(c, d))))
f = (a - 1) - (((a - 1) // c) + ((a - 1) // d) - ((a - 1) // (c * d // math.gcd(c, d))))
ans = e - f
print(ans)
import fractions
a, b, c, d = map(int, input().split())
p = b//c - (a-1)//c 
q = b//d - (a-1)//d 
#a,bの最小公倍数
def lcm(a, b):
  return a * b // fractions.gcd (a, b)
e = lcm(c, d)
r = b//e - (a-1)//e 
f = b - a + 1
p = f - p
q = f - q
r = f - r

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

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

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

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

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

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

cd = lcm(c, d)

b_c = b//c
b_d = b//d
b_cd = b//cd
bb = b - (b_c + b_d - b_cd)

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//cd
aa = (a-1) - (a_c + a_d - a_cd)

print(bb-aa)
from fractions import gcd

a, b, c, d = map(int, input().split())
g = int(c * d / gcd(c, d))
print((b - b // c - b // d + b // g) - ((a-1) - (a-1) // c - (a-1) // d + (a-1) // g))
def gcd(a, b):
    if a > b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

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

a, b, c, d = map(int, input().split())
a -= 1
e = lcm(c, d)
print(b - a - (b // d - a // d) - (b // c - a // c) + (b // e - a // e))
def gcd(n,m):
    if(n%m==0): return m
    else: return gcd(m,n%m)
a,b,c,d = map(int,input().split())
a-=1
x = b-b//c-b//d+b//(c*d//gcd(c,d))
y = a-a//c-a//d+a//(c*d//gcd(c,d))
print(x-y)
import math

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

m = b//c + (-a//c)
n = b//d + (-a//d)
g = c * d // math.gcd(c, d)
p = b//g + (-a//g) 
print(b-a+1-(m+1+n+1-(p+1)))
from fractions import gcd

A, B, C, D = map(int, input().split())
lcm = C*D//gcd(C,D)
#def count(n):
 # c = (B-A)//n
  #if A%n > B%n or A%n == 0:
   # c += 1
  #return c

#c = B-A+1-count(C)-count(D)+count(lcm)
def count2(A):
  c = A - A//C - A//D + A//lcm
  return c

c = count2(B)-count2(A-1)
print(int(c))
from fractions import gcd

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

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

def solve(n):
    x = n // c
    y = n // d
    z = n // lcm(c, d)
    return n - x - y + z

print(solve(b) - solve(a - 1))
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def mulc(t) :
    return (B//t - (A-1)//t)

print((B-A+1) - mulc(C) - mulc(D) + mulc(E))