Problem:
 Score : 300 points    Problem Statement You are given four integers A , B , C , and D . Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D .      Constraints  1\leq A\leq B\leq 10^{18}  1\leq C,D\leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  A  B  C  D       Output Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D .        Sample Input 1 4 9 2 3      Sample Output 1 2  5 and 7 satisfy the condition.       Sample Input 2 10 40 6 8      Sample Output 2 23       Sample Input 3 314159265358979323 846264338327950288 419716939 937510582      Sample Output 3 532105071133627368

Solution (Python):
import fractions

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


b_c = B // C
b_d = B // D


b_c_d = B // ((C*D)//fractions.gcd(C,D))


a_c = (A-1) // C
a_d = (A-1) // D


a_c_d = (A-1) // ((C*D)//fractions.gcd(C,D))


count = b_c + b_d - b_c_d - (a_c + a_d - a_c_d)

ans = B-A+1 - count
print(int(ans))

Solution (Python):
import fractions

a, b, c, d = map(int, input().split())
cdiv = b//c - (a-1)//c
ddiv = b//d - (a-1)//d
e =  c*d // fractions.gcd(c, d)
ediv = b//e - (a-1)//e
count = b-a+1 - (cdiv + ddiv - ediv)
print(count)

Solution (Python):
import fractions

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

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

print((b-a+1) - (bm-am))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

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

def F(N):
    
    x = N//C
    x += N//D
    lcm = C*D//gcd(C,D)
    x -= N//lcm
    return N-x

answer = F(B) - F(A-1)
print(answer)

Solution (Python):
import fractions
A, B, C, D = map(int, input().split())
CD = int((C*D)/fractions.gcd(C, D))

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

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


a_c=(a-1)//c
a_d=(a-1)//d

b_c=b//c
b_d=b//d

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

a_cd = (a-1)//cd
b_cd = b//cd

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

Solution (Python):
import fractions
a,b,c,d = map(int, input().split())

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

print(int(count))

Solution (Python):

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

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

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

def cntNum(n, x, y):
    return n - (n//x+n//y-n*gcd(x, y)//(x*y))


if A%C != 0 and A%D:
    print(cntNum(B, C, D) - cntNum(A, C, D) + 1)
else:
    print(cntNum(B, C, D) - cntNum(A, C, D))

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

import fractions

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

lcmcd=lcm(c,d)
divc=b//c-(a-1)//c
divd=b//d-(a-1)//d
divcd=b//lcmcd-(a-1)//lcmcd

print(b-a+1-divc-divd+divcd)

Solution (Python):
def gcd(x,y):
    x,y = max(x,y),min(x,y)
    while x != 0:
        y,x = x, y%x
    return y

def solve():
    a,b,c,d = map(int, input().split())
    cc = b//c - (a-1)//c
    dd = b//d - (a-1)//d
    e = c*d//gcd(c,d)
    cd = b//e - (a-1)//e
    print(b-a+1 - cc - dd + cd)

if __name__ == '__main__':
    solve()

Solution (Python):
a,b,c,d=map(int,input().split())
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a_0=(a-1)//c
a_1=(a-1)//d
a_2=(a-1)//lcm(c,d)
n=a_0+a_1-a_2

b_0=b//c
b_1=b//d
b_2=b//lcm(c,d)
m=b_0+b_1-b_2


print(b-a+1-(m-n))

Solution (Python):
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)
count = (B // C - (A-1) // C) + (B // D - (A-1) // D) - (B // lcm_CD - (A-1) // lcm_CD)
    
print((B - A + 1) - count)

Solution (Python):
def lmn(a,b):
    ans=a*b
    while b>0:
        tmp=b
        b=a%b
        a=tmp
    return ans//a

A,B,C,D=map(int,input().split())
print((B-A+1)-(B//C+B//D-B//lmn(C,D))+((A-1)//C+(A-1)//D-(A-1)//lmn(C,D)))

Solution (Python):
A,B,C,D=list(map(int,input().split()))
x=max(C,D)
y=min(C,D)
if x%y==0:
    gcd=C*D//y
else:
    while x%y!=0:
        z=x%y
        x=y
        y=z
    gcd=C*D//z
print(B-A+1-(B//C-(A-1)//C+B//D-(A-1)//D-B//gcd+(A-1)//gcd))

Solution (Python):
from fractions import gcd

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

e = c * d // gcd(c, d)
rest = (b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//e - (a-1)//e)
ans = b-a+1 - rest

print(ans)

Solution (Python):
from fractions import gcd


def lcm(p, q):
    return p * q // gcd(p, q)


def anti_division():
    a, b, c, d = map(int, input().split())
    numbers = b - a + 1
    cd_gcd = lcm(c, d)
    a_multiples = [a // min(c, d), a // max(c, d)]
    b_multiples = [b // min(c, d), b // max(c, d)]
    gcd_multiples = [a // cd_gcd, b // cd_gcd]
    ans = numbers - ((b_multiples[1] - a_multiples[1]) + (b_multiples[0] - a_multiples[0]) - (
            gcd_multiples[1] - gcd_multiples[0]))
    if a % c == 0:
        ans -= 1
    if a % d == 0:
        ans -= 1
    if a % cd_gcd == 0:
        ans += 1
    print(ans)


if __name__ == '__main__':
    anti_division()

Solution (Python):
import fractions
a,b,c,d=map(int,input().split())
x=c*d//fractions.gcd(c,d)
print(b-~-a-(b//c-~-a//c)-(b//d-~-a//d)+b//x-~-a//x)

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

def gcd(m,n):
	while n!=0:
		m,n = n,m % n
	return m

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

CD = lcm(C,D)

supC = B // C
supD = B // D
supCD = B // (CD)

infC = (A-1) // C
infD = (A-1) // D
infCD = (A-1) // (CD)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

Solution (Python):
from fractions import gcd
def lcm(a, b):
  return a * b // gcd (a, b)
A,B,C,D = map(int,input().split())
cnt_c = B // C - (A - 1) // C
cnt_d = B // D - (A - 1) // D
cnt_cd = B // lcm(C,D) - (A - 1) // lcm(C,D)
print(B - A + 1 - (cnt_c + cnt_d - cnt_cd))

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





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

def n_multiple(x):
    return B//x - ceil(A,x) + 1

def lcd(x,y):
    while y>0:
        x,y = y, x%y
    return(x)

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

print(int((B-A+1) - (n_multiple(C)+n_multiple(D)-n_multiple(gcd(C,D)))))

Solution (Python):
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())

c_m = b//c - (-(-a//c)) +1
d_m = b//d  - (-(-a//d)) + 1
cd = lcm(c,d)
cd_m = b//(cd) - (-(-a//(cd))) + 1

print(b-a+1 -(c_m + (d_m -cd_m)*(d%c != 0)))

Solution (Python):
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):
    g = gcd(a, b)

    return a * (b // g)


def f(n):
    return n - n // C - n // D + n // lcm(C, D)


def main():
    print(f(B) - f(A - 1))
    return


main()

Solution (Python):
def getDivisableCount(min_bound, max_bound, div):
    return max_bound // div - (min_bound - 1) // div

def LCM(a, b):
    return a * b // GCD(a, b)

def GCD(a, b):
    if a > b:
        a, b = b, a
    while b % a != 0:
        a, b = b % a, a
    return a

if __name__ == '__main__':
    A, B, C, D = [int(i) for i in input().split()]
    ret = (B - A + 1) - getDivisableCount(A, B, C) - getDivisableCount(A, B, D) + getDivisableCount(A, B, LCM(C, D))
    print(ret)

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


def lcm(a, b):
    g = gcd(a, b)

    return a * (b // g)


def main():
    A, B, C, D = map(int, input().split())
    c = B // C - (A - 1) // C
    d = B // D - (A - 1) // D
    tmp = lcm(C, D)
    both = B // tmp - (A - 1) // tmp
    print(B - A + 1 - c - d + both)
    return


main()

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

Solution (Python):

import fractions




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


def main():
    A, B, C, D = map(int, input().split())
    first = B // C - (A - 1) // C
    second = B // D - (A - 1) // D
    tmp = lcm(C, D)
    both = B // tmp - (A - 1) // tmp
    print(B - A + 1 - first - second + both)
    return


main()

Solution (Python):

import fractions




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


def main():
    A, B, C, D = map(int, input().split())
    first = B // C - A // C
    first += 1 if A % C == 0 else 0
    second = B // D - A // D
    second += 1 if A % D == 0 else 0
    tmp = lcm(C, D)
    both = B // tmp - A // tmp
    both += 1 if A % tmp == 0 else 0
    print(B - A + 1 - first - second + both)
    return


main()

Solution (Python):


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

def gcd(a,b):
    ans=1
    for i in range(1,int(min(a,b)**0.5)+1):
        
        if a%i==0 and b%i==0:
            ans=max(ans,i)
        temp=min(a,b)//i
        if a%temp==0 and b%temp==0:
            ans=max(ans,temp)
    return ans

num1=A-A//C-A//D+(A//(C*D//gcd(C, D)))
num2=B-B//C-B//D+(B//(C*D//gcd(C, D)))

print(num2-num1)

Solution (Python):
import fractions
a,b,c,d = map(int, input().split())
cc = b//c - (a-1)//c
dd = b//d - (a-1)//d
gcd = int(c*d / fractions.gcd(c, d))
cd = b//gcd - (a-1)//gcd

print((b-a+1) + cd - cc -dd)

Solution (Python):
import fractions
a,b,c,d = map(int, input().split())
cc = b//c - (a-1)//c
dd = b//d - (a-1)//d
gcd = int(c*d / fractions.gcd(c, d))
cd = b//gcd - (a-1)//gcd

print((b-a+1) + cd - cc -dd)

Solution (Python):
import fractions
a, b, c, d = map(int,input().split())
print(b - a + 1 - (b // c + b // d - b // ((c * d) // fractions.gcd(c, d)) - ((a-1) // c + (a-1) // d - (a-1) // ((c * d) // fractions.gcd(c, d)))))

Solution (Python):
from fractions import gcd
a, b, c, d = map(int, input().split())
e = c * d // gcd(c, d)
tmp = []
for i in (c, d, e):
    if not a % i:
        l = a
    else:
        l = a + (i - (a % i))
    r = b - b % i
    tmp.append((r - l) // i + 1)

print((b-a+1) - tmp[0] - tmp[1] + tmp[2])

Solution (Python):
A,B,C,D = map(int,input().split())
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
E = C * D // gcd(C,D)

dif = B - A + 1
rc = B//C + (-A//C) + 1
rd = B//D + (-A//D) + 1
re = B//E + (-A//E) + 1
x = dif - rc - rd + re
print(x)

Solution (Python):
from fractions import gcd

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

def calc(div):
  return B // div - (A - 1) // div

print((B - A + 1) - (calc(C) + calc(D) - calc(C * D // gcd(C, D))))

Solution (Python):

import sys


def get_min_koubai(a, b):
    if a > b:
        tmp = b
        b = a
        a = tmp

    x = a * b
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b

    return x // b


def solve(A: int, B: int, C: int, D: int):
    
    
    
    
    min_koubai = get_min_koubai(C, D)
    b1 = B // C
    b2 = B // D
    b3 = B // min_koubai
    b_count = b1 + b2 - b3

    
    
    a1 = (A - 1) // C
    a2 = (A - 1) // D
    a3 = (A - 1) // min_koubai
    a_count = a1 + a2 - a3

    
    
    print(B - (A - 1) - (b_count - a_count))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    D = int(next(tokens))  
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd

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

ac=(a-1)//c
ad=(a-1)//d
alcm=(a-1)//lcm

bc=b//c
bd=b//d
blcm=b//lcm

print(n-((bc-ac)+(bd-ad)-(blcm-alcm)))

Solution (Python):
def solve():
    def gcd(x,y):
        while y != 0:
            x , y = y , x % y
        return x

    A,B,C,D = map(int ,input().split())
    A -= 1
    gcd_val = gcd(C , D)
    lcm_val = C * D // gcd_val
    ReduceFromB = B - (B // C + B // D - B // lcm_val)
    ReduceFromA = A - (A // C + A // D - A // lcm_val)
    print(ReduceFromB - ReduceFromA)

solve()

Solution (Python):
from fractions import gcd

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

Solution (Python):

from fractions import gcd
a,b,c,d = map(int,input().split())
n = b-a+1
cd = (c*d)//gcd(c,d)

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

b_c = b//c
b_d = b//d
b_cd = b//cd

print(n- ((b_c-a_c)+(b_d-a_d)-((b_cd-a_cd))))

Solution (Python):
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x==0:
    return y
  else:return gcd(y%x,x)

def f(a,s,d):
  x=s*d//gcd(s,d)
  return a-a//s-a//d+a//x

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

Solution (Python):

def GCD(x,y):
    x,y=max(x,y),min(x,y)
    if x%y==0:
        return y
    else:
        return GCD(y,x%y)

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

L=(C*D)//GCD(C,D)
X=B//C-(A-1)//C
Y=B//D-(A-1)//D
Z=B//L-(A-1)//L
print((B-A+1)-(X+Y-Z))

Solution (Python):
import fractions
A,B,C,D = map(int, input().split())
BC = B//C
if A%C == 0:
    AC = A//C-1
else:    
    AC = A//C
BD = B//D
if A%D == 0:
    AD = A//D - 1
else:
    AD = A//D
GCD = C*D//fractions.gcd(C,D)
BB = B//GCD
if A%GCD == 0:
    AA = A//GCD - 1
else:
    AA = A//GCD
print((B-A+1)-(BC-AC)-(BD-AD)+(BB-AA))

Solution (Python):
from fractions import gcd


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

Solution (Python):
import fractions
def answer(x, i, j):
    lcm = (i * j) // fractions.gcd(i, j)
    xi = x // i
    xj = x // j
    xlcm = x // lcm
    return x - xi - xj + xlcm
a, b, c, d = map(int, input().split())
ans = answer(b, c, d) - answer(a-1, c, d)
print(ans)

Solution (Python):
A, B, C, D = map(int, input().split())
def gcd(a, b):
    if a < b:
        a, b = b, a
    a, b = b, a % b
    if b == 0 :
        return a
    else:
        return gcd(a, b)
cd = C * D //gcd(C, D)
print(B - B // C - B // D + B // cd - A + 1 + (A - 1) // C + (A - 1)// D - (A - 1)// cd)

Solution (Python):
from fractions import gcd

def get_num(div):
  num = (B)//div - (A-1)//div
  return num

A,B,C,D = map(int,input().split())
print(B-A+1-get_num(C)-get_num(D)+get_num(C*D//gcd(C,D)))

Solution (Python):
import fractions
a, b, c, d = map(int, input().split())
cd = c * d // (fractions.gcd(c, d))
s = ((a - 1) // c) + ((a - 1) // d) - ((a - 1) // cd)
e = (b // c) + (b // d) - (b // cd)
print((b - (a - 1)) - (e - s))

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

def gcd(a, b):
  if b > a:
    a, b = b, a
  a,b = b, a % b
  if b == 0:
    return a
  else:
    return gcd(a, b)
G = C * D // gcd(C, D)

print (B -B // C - B // D + B // G -(A-1)+ (A-1) // C + (A-1) // D - (A-1) // G)

Solution (Python):
A,B,C,D = map(int,input().split())
def dev_num(X):
  m = A//X if A%X == 0 else A//X + 1
  n = B//X
  return n-m+1
def gcd(x,y):
  if x>y:
    x,y=y,x
  if y%x == 0:
    return x
  else:
    return gcd(y%x,x)
def lcm(x,y):
  return x*y//gcd(x,y)

print(B-A+1 - dev_num(C) - dev_num(D) + dev_num(lcm(C,D)))

Solution (Python):
a, b, c, d = [int(i) for i in input().split()]

def gcd(x, y):
	if x % y == 0:
		return y
	return gcd(y, x % y)
	
def num(x, c, d):
	return x - x // c - x // d + x // (c * d // gcd(c, d))

undera = num(a - 1, c, d)
underb = num(b, c, d)
print(underb - undera)

Solution (Python):
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    A, B, C, D = map(int, input().split())
    
    A_C = (A-1)//C
    A_D = (A-1)//D
    A_CD = (A-1)//((C*D)//gcd(C, D))
    A_nCD = (A-1) - (A_C + A_D - A_CD)

    B_C = B//C
    B_D = B//D
    B_CD = B//((C*D)//gcd(C, D))
    B_nCD = B - (B_C + B_D - B_CD)

    print(B_nCD - A_nCD)


if __name__ == '__main__':
    main()

Solution (Python):
import fractions
a,b,c,d=map(int,input().split())
ans=0
ca=[]
da=[]
cda=[]
minimunc=-(-a//c)
minimund=-(-a//d)
minimuncd=-(-a//((c*d)//fractions.gcd(c,d)))
maximunc=b//c
maximund=b//d
maximuncd=b//((c*d)//fractions.gcd(c,d))
totalc=maximunc-minimunc+1
totald=maximund-minimund+1
totalcd=maximuncd-minimuncd+1

print((b-a+1)-(totalc+totald-totalcd))

Solution (Python):
def gcd(x,y):
	while y:
		x,y = y,x % y
	return x


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

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

if a%c == 0:
	start_c = a
else:
	start_c = a + c - a % c
if a%d == 0:
	start_d = a
else:
	start_d = a + d - a % d
if a%cd == 0:
	start_cd = a
else:
	start_cd = a + cd - a % cd

end_c = b - b % c
end_d = b - b % d
end_cd = b - b % cd

if b >= c:
	ans += (end_c - start_c) // c + 1
if b >= d:
	ans += (end_d - start_d) // d + 1
if b >= cd:
	ans -= (end_cd - start_cd) // cd + 1

print(b-a+1-ans)

Solution (Python):
import fractions

A = list(map(int, input().split())) 
a = A[0]
b = A[1]
c = A[2]
d = A[3]
aa = a-1
all = b-aa
cdiv = b//c - aa//c
ddiv = b//d - aa//d
cd_lcm = c*d // (fractions.gcd(c,d))

cddiv = b//cd_lcm - aa//cd_lcm

print(all-cdiv-ddiv+cddiv)

Solution (Python):
import fractions as math
a,b,c,d = map(int,input().split())
"""
aからbまでの倍数を求めるのではなく、
0からa-1,0からbまでの２つに分けてそれぞれ出して差で求める。
"""

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


print(b-a-(c+d-cd))

Solution (Python):
import fractions
a, b, c, d = map(int, input().split())

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

total = b - (b//c + b//d - b//lcm)
total_del = a-1 -((a-1)//c + (a-1)//d - (a-1)//lcm)

print(total - total_del)

Solution (Python):
from fractions import gcd

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

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

Solution (Python):
from fractions import gcd

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

Solution (Python):
import fractions
a, b, c, d = map(int, input().split())
div_c = b//c + (-a//c) + 1
div_d = b//d + (-a//d) + 1
div_cd = b//(c*d//fractions.gcd(c, d)) + (-a//(c*d//fractions.gcd(c,d))) + 1
print(b-a+1 - div_c - div_d + div_cd)

Solution (Python):
from fractions import gcd
from math import ceil
def div(n,a,b):
    m = b//n-(a-1)//n
    
    return max(m,0)
a,b,c,d = map(int,input().split())
e = c*d//gcd(c,d)
print(b-a+1-(div(c,a,b) + div(d,a,b) - div(e,a,b)))

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

Solution (Python):

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

Solution (Python):
import fractions
A, B, C, D = map(int, input().split())

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

b_n = B//C + B//D - B//lcm(C,D)
a_n = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
ans_n = b_n - a_n
print(int(B-A+1-ans_n))

Solution (Python):

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

def lcm(x, y):
    return (x * y) // gcd(x, y)
  
A,B,C,D = map(int,input().split())









all = B-A+1

if(A%C == 0): c_count = B//C-A//C+1
else: c_count = B//C-A//C

if(A%D == 0): d_count = B//D-A//D+1
else: d_count = B//D-A//D

C_D = lcm(C,D)
if(A%C_D == 0): c_d_count = B//C_D-A//C_D+1
else: c_d_count = B//C_D-A//C_D

ans = all - (c_count+d_count-c_d_count)
print(ans)

Solution (Python):
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)))))

Solution (Python):
import fractions
a,b,c,d=map(int,input().split())

f1=fractions.gcd(c,d)
f2=c*d//f1

a=a-1
aa=a-a//c-a//d+a//f2
bb=b-b//c-b//d+b//f2

print(bb-aa)

Solution (Python):
A, B, C, D = map(int,input().split())
ans = 0
x1c = B // C
x1d = B // D
x2c = (A-1) // C
x2d = (A-1) // D
def gcd(x,y):
    if x < y:
        z = x
        x = y
        y = z
    while y != 0:
        x, y = y, x%y
    return x
g = gcd(C,D)
l = (C*D) // g
x1cd = B // l
x2cd = (A-1) // l
ans_B = B - (x1c+x1d-x1cd)
ans_A = (A-1) - (x2c+x2d-x2cd)
ans = ans_B - ans_A
ans = int(ans)
print(ans)

Solution (Python):
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

E = lcm(C, D)
count_A = (A - 1) - (A - 1)//C - (A - 1)//D + (A - 1)//E
count_B = B - B//C - B//D + B//E

print(count_B - count_A)

Solution (Python):
A, B, C, D = map(int, input().split())
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)

print((B-A+1) - ((B//C - (A-1)//C) + (B//D - (A-1)//D) - (B//lcm(C, D) - (A-1)//lcm(C, D))))

Solution (Python):
from fractions import gcd

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

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

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

Solution (Python):
a,b,c,d = map(int,input().split())
ans = b - a + 1
x = c * d
e = c
f = d
if e < f:
    e = f
    f = c
r = e % f
while r != 0:
    e = f
    f = r
    r = e % f
x //= f
ans -= b // c - (a-1) // c + b // d - (a-1) // d
ans += b // x - (a-1) // x
print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
def gcd(x,y):
  z=x%y
  if z==0:
    return y
  else:
    return gcd(y,z)
ans=(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)))
print(ans)

Solution (Python):
import fractions

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

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

ans = c_num + d_num - lcm_num

print(b-a+1-ans)

Solution (Python):
from sys import stdin
import fractions
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = fractions.gcd(c, d)
koubai = c * d // fractions.gcd(c, d)
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)

Solution (Python):

def gcd(x,y):
    
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a,b,c,d=map(int,input().split())
a-=1
def f(i):
    ai=a%i
    bi=b%i
    if ai==bi:
        return (b-a)//i
    elif ai>bi:
        return (b-a)//i+1
    else:
        return (b-a)//i
C=c//gcd(c,d)
D=d//gcd(c,d)
H=C*D*gcd(c,d)
print(b-a-f(c)-f(d)+f(H))

Solution (Python):
A,B,C,D=map(int,input().split())
c_dividable=B//C-(A-1)//C
d_dividable=B//D-(A-1)//D
def gcd(a,b):
  if a==b:
    return a
  else:
    if a%b==0:
      return b
    while a%b!=0:
      return gcd(b,a%b)
v=C*D//gcd(C,D)
cd_dividable=B//v-(A-1)//v
print(B-A+1-(c_dividable+d_dividable-cd_dividable))

Solution (Python):
from fractions import gcd

A, B, C, D = map(int, input().split())
C_div = B // C - (A - 1) // C
D_div = B // D - (A - 1) // D
CD = C * D // gcd(C, D)
CD_div = B // CD - (A - 1) // CD
print(B - A + 1 - C_div - D_div + CD_div)

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

from fractions import gcd

def f(i, l, r):
  return r//i - (l-1)//i

cnt = f(c, a, b) + f(d, a, b) - f((c*d)//gcd(c, d), a, b)

print(b - a + 1 - cnt)

Solution (Python):
import fractions
A, B, C, D = map(int, input().split())
A = A-1
f=fractions.gcd(C,D)
f2=C*D//f

Aans = A - (A//C + A//D - A//f2)
Bans = B - (B//C + B//D - B//f2)
print(Bans- Aans)

Solution (Python):
import fractions

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

X = (C * D) // fractions.gcd(C, D)
ans = (B - A + 1)\
      - (B // C - A // C)\
      - (B // D - A // D)\
      + (B // X - A // X)
if A % C == 0:
      ans -= 1
if A % D == 0:
      ans -= 1
if A % X == 0:
      ans += 1

print(ans)

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

def andiv(M,N):
    return((N//M) * (M-1) + N%M)

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

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(int(E-F))

Solution (Python):
import fractions

def lcm(a,b):
    res = a*b // fractions.gcd(a,b)
    return res
def f(x,y,z):
    res = x
    res -= x//y
    res -= x//z
    res += x//lcm(y,z)
    return res


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

Solution (Python):
a, b, c, d = list(map(int, input().split()))
import fractions
a_amount =  (a-1) - ((a-1) // d) - ((a-1)//c) + ((a-1) // ((c*d)//fractions.gcd(c,d)))
b_amount =  b - (b // d) - (b//c) + (b // ((c*d)//fractions.gcd(c,d)))
print(b_amount - a_amount)

Solution (Python):
import fractions


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


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

c_multiple_last = b // c
d_multiple_last = b // d
cd_multiple_last = b // lcm(c, d)

c_multiple_first = (a-1) // c
d_multiple_first = (a-1) // d
cd_multiple_first = (a-1) // lcm(c, d)

c_count = c_multiple_last - c_multiple_first
d_count = d_multiple_last - d_multiple_first
cd_count = cd_multiple_last - cd_multiple_first

a_to_b_count = b - a + 1
ans = a_to_b_count - (c_count + d_count - cd_count)
print(ans)

Solution (Python):
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 = map(int,input().split())
li=[]
gc = lcm(c,d)
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

Solution (Python):
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    cd = b // c - (a - 1) // c
    dd = b // d - (a - 1) // d
    gcd = c * d // fractions.gcd(c, d)
    gcdd = b // gcd - (a - 1) // gcd
    print(b - a + 1 - cd - dd + gcdd)


if __name__ == '__main__':
    slove()

Solution (Python):
from fractions import gcd 
import sys

l, r, c, d = map(int, sys.stdin.readline().split())

count = 0

first = (l + c - 1)//c 
last = r//c 

count += last - first + 1

first = (l + d - 1)//d 
last = r//d 
count += last - first + 1

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

first = (l + lcm - 1)//lcm 
last = r // lcm
count -= last - first + 1


print(r - l - count + 1)

Solution (Python):
a,b,c,d = map(int,input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
cd = lcm(c,d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))

Solution (Python):
import fractions

A,B,C,D =map(int,input().split())
c_i =  ((A+C-1)//C)
c_f = B//C
c_dis = c_f-c_i+1 if c_f-c_i >= 0 else 0

d_i = ((A+D-1)//D)
d_f = B//D
d_dis = d_f-d_i+1 if d_f-d_i>= 0 else 0

cd = C*D//fractions.gcd(C,D)
cd_i = ((A+cd-1)//cd)
cd_f = B//cd
cd_dis = cd_f-cd_i+1 if cd_f-cd_i >= 0 else 0

ans = B-A+1 - c_dis - d_dis+ cd_dis

print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
def kosuu(a,b,c):
    if a%c==0:
        return (b-a)//c+1
    else:
        return(b-(a+(c-a%c)))//c+1

g=0
c1=c
d1=d
while c1!=0 and d1!=0:
    if c1<=d1:
        d1=d1%c1
    else:
        c1=c1%d1
if c1!=0:
    g=c1
else:
    g=d1

print(b-a+1-kosuu(a,b,c)-kosuu(a,b,d)+kosuu(a,b,c*d//g))

Solution (Python):
a,b,c,d=map(int,input().split())
def kosuu(a,b,c):
    if a%c==0:
        return (b-a)//c+1
    else:
        return(b-(a+(c-a%c)))//c+1

l=0
c1=c
d1=d
while c1!=0 and d1!=0:
    if c1<=d1:
        d1=d1%c1
    else:
        c1=c1%d1
if c1!=0:
    l=c1
else:
    l=d1

print(b-a+1-kosuu(a,b,c)-kosuu(a,b,d)+kosuu(a,b,c*d//l))

Solution (Python):
import fractions
m = list(map(int,input().split()))
c=[]
c.append(m[2])
c.append(m[3])
f=fractions.gcd(m[3],m[2])
p=(m[3]*m[2])// f
c.append(p)
         
a=[]
a.append(m[0]-1)
a.append(m[1])

d=[]
for i in range(3):
    for j in range(2):
        d.append(a[j]//c[i])
        
x = m[0]-1 - d[0]-d[2]+d[4]
y = m[1] - d[1]-d[3]+d[5]
print(int(y-x))

Solution (Python):
from fractions import gcd

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


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


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


print(cantdiv(b) - cantdiv(a - 1))

Solution (Python):
L = list(map(int, input().split()))

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

def count_between(x, a, b):
    c = x
    l = (a * b) // gcd(a, b)
    c = c - x // a - x // b + x // l
    return c


print(count_between(L[1], L[2], L[3]) - count_between(L[0] - 1, L[2], L[3]))

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

from fractions import gcd


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


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

A -= 1


nb = B - B//C - B//D + B//lcm(C, D)
na = A - A//C - A//D + A//lcm(C, D)

print(nb - na)

Solution (Python):
a, b, c, d = map(int, input().split())
a -= 1
def gcd(c,d):
    while (c%d):
        t = c%d
        c, d = d, t
    return d

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

b_ans = b - (b//c + b//d - b//lcm)
a_ans = a - (a//c + a//d - a//lcm)

print(b_ans - a_ans)

Solution (Python):
import fractions
a, b, c, d = map(int,input().split())
e = c*d//fractions.gcd(c,d)
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

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

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

mc = b // c - (a-1) // c
md = b // d - (a-1) // d
mcd = b // (c*d//gcd(c, d)) - (a-1) // (c*d//gcd(c, d))

print(int((b - a + 1) - mc - md + mcd))

Solution (Python):
def gcd(x, y):
  while y!=0:
    x,y=y,x%y
  return x

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

Solution (Python):
import fractions

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

Solution (Python):
A, B, C, D = map(int, input().split())
import fractions
G = (C*D)//fractions.gcd(C, D)
print(B - A + 1 - ( B//C - (A-1)//C + B//D - (A-1)//D - B//G + (A-1)//G ))

Solution (Python):
def gcd_base(x,y):
    while y!=0:
        x,y = y,x%y
    return x

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

a,b,c,d = map(int,input().split())
ctmp = b//c - (a-1)//c
dtmp = b//d - (a-1)//d
lcm_cd = lcm_base(c,d)
cdtmp = b//lcm_cd - (a-1)//lcm_cd
ans = (b - a + 1) - (ctmp + dtmp - cdtmp)
print(ans)

Solution (Python):
import copy
import sys
from _operator import itemgetter
from collections import Counter
from fractions import gcd
from math import log2, pi, ceil

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

a, b, c, d = na()
x1 = a // c
y1 = a // d
z1 = a // (lcm(c, d))

x2 = b // c
y2 = b // d
z2 = b // (lcm(c, d))

ans = b - (x2 + y2 - z2)  - (a - (x1 + y1 - z1))
if a % c != 0 and a % d != 0:
    ans += 1
print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
p=c
q=d
e=b//c-(a-1)//c
f=b//d-(a-1)//d
while c%d!=0 and d%c!=0:
    if c>d:
        c=c-d
    elif c<=d:
        d=d-c
if c>d:
    gcm=d
else:
    gcm=c
lcm=(p*q)//gcm
g=b//lcm-(a-1)//lcm
ans=b-a+1-e-f+g
print(int(ans))