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



Sample input:
4 9 2 3


Sample output:
2

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int, input().split(' '))
cm = 0  # common multiple
num = a

if c == d:
  cm = math.ceil(b/c) - math.ceil(a/c)
else:
  lcm = c*d//math.gcd(c,d)
  cn = lcm//c
  dn = lcm//d
  for i in range(a//lcm, b//lcm+1):
    if i*lcm <= b:
      cm += 1
    for j in range(1, cn):
      if i*lcm + j*c <= b:
        cm += 1
    for k in range(1, dn):
      if i*lcm + k*d <= b:
        cm += 1

ans = b-a+1 - cm
print(ans)

Submission status: Runtime Error

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

e=int(c*d/math.gcd(c,d))
x1=(a-1)//c
x2=b//c
y1=(a-1)//d
y2=b//d
z1=(a-1)//e
z2=b//e


print(int(b-a+1-(x2-x1+y2-y1-(z2-z1))))

Submission status: Runtime Error

Solution code:
import math
import fractions

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

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = max(math.ceil(A / X),0)
    maxX = max(math.floor(B / X),0)
    return maxX - minX + 1

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) % min(C,D) == 0 :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans + 1)
elif A % C == 0 or A % C == 0 :
    print(z)
else :
    ans = B - A + 1

    # 最小公倍数
    Z = int(C * D / fractions.gcd(C,D))

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Runtime Error

Solution code:
import math
# input process
inputData = input().split()
A = int(inputData[0])
B = int(inputData[1])
C = int(inputData[2])
D = int(inputData[3])

C_q_num = (B // C) - (A // C)
D_q_num = (B // D) - (A // D)
CD_lcm = (C * D) // math.gcd(C, D)
CD_q_num = (B // CD_lcm) - (A // CD_lcm) + 1
print((B-A) - C_q_num - D_q_num + CD_q_num)

Submission status: Runtime Error

Solution code:
import fractions

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

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (int(A/mod) +1)) * mod

    end = (int(B /mod)) * mod

    return (end - start) / mod +1

ans =(B-A+1)-(num_of_mod0(C) + num_of_mod0(D)- num_of_mod0(lcm(C,D)))
ans = int(ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
a -= 1
x = b // c + b // d - b // (c*d/max(math.gcd(c,d), 1))
y = a // c + a // d - a // (c*d/max(math.gcd(c,d), 1))
print(int(b-a-x+y))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
A, B, C, D = map(int, input().split())
lcmofCD = int(C * D / math.gcd(C, D))
divofAbyC = A // C
divofAbyD = A // D
divofBbyC = B // C
divofBbyD = B//D
divofBbylcm = B // lcmofCD
divofAbylcm = A // lcmofCD
ansofA = A - (divofAbyC + divofAbyD - divofAbylcm)
ansofB = B-(divofBbyC+divofBbyD-divofBbylcm)
ans = ansofB-ansofA

print("{}".format(ans+1))

Submission status: Runtime Error

Solution code:
import math

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


a,b,c,d = map(int,input().split())
tn = b-a+1


cn = (b//c)-((a-1)//c)
dn = (b//d)-((a-1)//d)

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

print(tn-cn-dn+cdn)

Submission status: Runtime Error

Solution code:
# Recursive function to return gcd of a and b 
def gcd(a,b): 
	
	# Everything divides 0 
	if (a == 0): 
		return b 
	if (b == 0): 
		return a 

	# base case 
	if (a == b): 
		return a 

	# a is greater 
	if (a > b): 
		return gcd(a-b, b) 
	return gcd(a, b-a) 

#from math import gcd
a,b,c,d=map(int,input().split(' '))
r1=b-b%c
if a%c!=0:
	l1=a-a%c+c
else:
	l1=a
r2=b-b%d
if a%d!=0:
	l2=a-a%d+d
else:
	l2=a

lcm=(c*d)//gcd(c,d)
r3=b-b%lcm
if a%lcm!=0:
	l3=a-a%lcm+lcm
else:
	l3=a
nc=(r1-l1+c)//c
nd=(r2-l2+d)//d
nlcm=(r3-l3+lcm)//lcm
divi=nc+nd-nlcm
out=b-a+1
if c>a and c>b and d>a and d>b:
	print(0)
else:
	print(out-divi)

Submission status: Runtime Error

Solution code:
import numpy as np

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

count = 0

for i in np.append(np.array(range(A, B)), [B]):
    if not i % C == 0 and not i % D == 0:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
import fractions

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

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (int(A/mod) +1) * mod

    end = (int(B /mod) * mod

    return (end - start) / mod +1

ans =(B-A+1)-(num_of_mod0(C) + num_of_mod0(D)- num_of_mod0(lcm(C,D)))
ans = int(ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

minLcm = lcm(C, D)

divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CtoD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CtoD

print(answer)

Submission status: Runtime Error

Solution code:
import math

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


a,b,c,d = map(int,input().split())
tn = b-a+1


cn = (b//c)-((a-1)//c)
dn = (b//d)-((a-1)//d)

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



print(tn,cn,dn,cdn)
print(tn-cn-dn+cdn)

Submission status: Runtime Error

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


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

X = (B//C - (A-1)//C)
Y = (B//D - (A-1)//D)
Z = (B//E - (A-1)//E)


print(B - (X+Y-Z)-A + 1)

Submission status: Runtime Error

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

e = int(b // c)
f = int(a // c)
if f == a / c:
    g = e - f + 1
else:
    g = e - f

h = int(b // d)
i = int(a // d)
if i == a / d:
    j = h - i + 1
else:
    j = h - i

import math

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

k = int(b // cd)
l = int(a // cd)
if l == a / cd:
    m = k - l + 1
else:
    m = k - l

ans = (b-a) + 1 - (g + j - m)
print(int(ans))

Submission status: Runtime Error

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

e=int(c*d/math.gcd(c,d))
x1=(a-1)//c
x2=b//c
y1=(a-1)//d
y2=b//d
z1=(a-1)//e
z2=b//e


#print(a,b,c,d,e,x1,x2,y1,y2,z1,z2)

print(b-a+1-(x2-x1+y2-y1-(z2-z1)))

Submission status: Runtime Error

Solution code:
import math

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

ans = 0

if c % d == 0:
    print((b - a + 1) - (b//d - a//d))
elif d % c == 0:
    print((b - a + 1) - (b//c - a//c))
else:
    tot = c * d // math.gcd(c, d)
    tmp = (b // d - a // d) + (b//c - a//c) - (b // tot - a // tot)
    print(int((b - a + 1) - tmp))

Submission status: Runtime Error

Solution code:
import math
x=list(map(int,input().split()))
a,b,c,d,p=x[0],x[1],x[2],x[3],0
G=int(c*d/math.gcd(c,d))
a1,a2,a3=0,0,0
if b/c-int(b/c)==0:
    a1=1
if b/d-int(b/d)==0:
    a2=1
if b/G-int(b/G)==0:
    a3=1
p=a1+a2+a3
print(b-a+1-math.ceil(b/c)+math.ceil(a/c)-math.ceil(b/d)+math.ceil(a/d)+math.ceil(b/G)-math.ceil(a/G)-p)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = (int(x) for x in input().split())
def kansu(x,y,z):
    sta = x
    end = y
    if sta%z != 0:
        sta = sta+(z-(sta%z))
    if end%z != 0:
        end = end-(end%z)
    ans = ((end-sta)/z) +1
    return ans
a1 = kansu(a,b,c)
a2 = kansu(a,b,d)
lcm = c*d/(math.gcd(c,d))
a3 = kansu(a,b,lcm)
print(int(b-a-a1-a2+a3+1))

Submission status: Runtime Error

Solution code:
import math

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

if C == D:
    duplicate = C
elif C > D and C % D == 0:
    duplicate = C
elif D > C and D % C == 0:
    duplicate = D
else:
    duplicate = C * D // math.gcd(C, D)

cCnt = (B - A) // C
dCnt = (B - A) // D
duplicateCnt = (B - A) // duplicate

print(B - A - cCnt - dCnt + duplicateCnt)

Submission status: Runtime Error

Solution code:
# coding: utf-8
from math import ceil, floor, gcd
A, B, C, D = map(int, input().split())
lcm = (C * D) // gcd(C, D)
# c_cnt = ceil((B) / C) - (A-1) // C
# d_cnt = ceil((B) / D) - (A-1) // D
# cd_cnt = ceil((B) / (lcm)) - (A-1) // (lcm)
c_cnt = B // C - (A-1) // C
d_cnt = B // D - (A-1) // D
cd_cnt = B // (lcm) - (A-1) // (lcm)
minus = c_cnt + d_cnt - cd_cnt
# print(c_cnt, d_cnt, cd_cnt)
print(B - A - minus + 1)

Submission status: Runtime Error

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


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

X = (B//C - (A-1)//C)
Y = (B//D - (A-1)//D)
Z = (B//E - (A-1)//E)

print(E)
print(X)
print(Y)
print(Z)
print(B - (X+Y-Z)-A + 1)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
a -= 1
x = b // c + b // d - b // (c*d/math.gcd(c,d))
y = a // c + a // d - a // (c*d/math.gcd(c, d))
print(int(b-a-x+y))

Submission status: Runtime Error

Solution code:
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)


minLcm = lcm(C, D)

answer = 10

# divisible_CD = (B // minLcm) - ((A - 1) // minLcm)
# 
# divisible_CtoD = (divisible_C + divisible_D) - divisible_CD
# 
# answer = AtoB - divisible_CtoD

print(answer)

Submission status: Runtime Error

Solution code:
import math

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

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

    diff = B - A
    count_c = diff // C
    count_d = diff // D
    count_union = diff // lcm(C, D)

    print(diff - count_c - count_d + count_union)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import ceil,gcd

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

a,b,c,d = map(int,input().split())
e = int(lcm(c,d))
t1 = max(0,int(b/c)-ceil(a/c)+1)
t2 = max(0,int(b/d)-ceil(a/d)+1)
t3 = max(0,int(b/e)-ceil(a/e)+1)
ans = t1+t2-t3
ans = b-a+1-ans
print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
s=0
start = a//c
end = b//c
a * b // math.gcd(a, b)
if start*c<a:
    s += end-(start+1)+1
else:
    s += end - start + 1
if d%c!=0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

    return gcd
last =c * d // gcd(c, d)
start = a//last
end = b//last
if start*c<a:
    s -= end-(start+1)+1
else:
    s -= end - start + 1
print((b-a+1)-s)

Submission status: Runtime Error

Solution code:
import math
import fractions

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

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) % min(C,D) == 0 :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans)
else :
    ans = B - A + 1

    # A以上B以下の数でXの倍数の個数
    def countX(X) :
        if X > B :
            return 0
        minX = max(math.ceil(A / X),0)
        maxX = max(math.floor(B / X),0)

        return maxX - minX + 1

    # 最小公倍数
    Z = int(C * D / fractions.gcd(C,D))

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int,input().split())
CD = int(C * D / math.gcd(C, D))
numC = int(B/C) - int((A-1)/C)
numD = int(B/D) - int((A-1)/D)
numCD = int(B/(CD)) - int((A-1)/(CD))
print(B - A + 1 - (numC + numD - numCD))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = list(map(int, input().split()))
c0 = math.floor(b/c) - math.ceil(a/c) + 1
d0 = math.floor(b/d) - math.ceil(a/d) + 1
lcm = c * d / math.gcd(c,d)
lcm0 = math.floor(b/lcm) - math.ceil(a/lcm) + 1
ans = (b - a + 1) - c0 - d0 + lcm0
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
setAB=set(range(A,B+1))
setC=range(A,B+1,C)
setD=range(A,B+1,D)
setCD=set(setC+setD)
ans=len(setAB)-len(setCD)
print(ans)

Submission status: Runtime Error

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

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

under_c = (A - 1) // C
under_d = (A - 1) // D
under_cd = (A - 1) // lcm_cd

top_c = B // C
top_d = B // D
top_cd = B // lcm_cd

ans = (B -
       (A - 1)) - (top_c - under_c) - (top_d - under_d) + (top_cd - under_cd)

print(ans)

Submission status: Runtime Error

Solution code:
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

minLcm = lcm(C, D)

divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CtoD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CtoD

print(answer)

Submission status: Runtime Error

Solution code:
import math

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

ans = 0

if c % d == 0:
    print((b - a + 1) - (b//d - a//d))
elif d % c == 0:
    print((b - a + 1) - (b//c - a//c))
else:
    tot = c * d / math.gcd(c, d)
    tmp = (b // d - a // d) + (b//c - a//c) - (b // tot - a // tot)
    print(int((b - a + 1) - tmp))

Submission status: Runtime Error

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

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

count = 0
for _ in range(a//c, (b+1)//c):
    count += 1

for _ in range(a//d, (b+1)//d):
    count += 1
for _ in range(a//lcm(c,d), (b+1)//lcm(c,d)):
    count -= 1

print(b+1-a-count)

Submission status: Runtime Error

Solution code:
import math
x=list(map(int,input().split()))
a,b,c,d,p=x[0],x[1],x[2],x[3],0
G=int(c*d/math.gcd(c,d))
a1,a2,a3,a4,a5,a6=0,0,0,0,0,0
if b/c-int(b/c)==0.0:
    a1=1
if b/d-int(b/d)==0.0:
    a2=1
if b/G-int(b/G)==0.0:
    a3=1
p=a1+a2+a3
print(b-a+1-math.ceil(b/c)+math.ceil(a/c)-math.ceil(b/d)+math.ceil(a/d)+math.ceil(b/G)-math.ceil(a/G)-p)

Submission status: Runtime Error

Solution code:

import math

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

U = B - A + 1

nA = ( math.floor(B / C) ) - (math.ceil(A / C)) +1

nB = ( math.floor(B / D) ) - (math.ceil(A / D)) +1

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

saisyoukoubaisuu = int(saisyoukoubaisuu)

nAB = (B//saisyoukoubaisuu) -(B//saisyoukoubaisuu) + 1

print( U -(nA + nB - nAB) )

Submission status: Runtime Error

Solution code:
from math import gcd
def lcm_func(x,y):
        return x*y//gcd(x,y)
a,b,c,d  = list(map(int,input().split()))
lcm_var = lcm_func(c,d)
size = (b-a+1)
print(size - ((int(b/c) - int(a/c)) + (int(b/d) - int(a/d)) - (int(b/lcm_var) - int(b/lcm_var))))

Submission status: Runtime Error

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

i = (b//c- a//c)
j = (b//d- a//d)

f=math.gcd(c,d)
f2= c * d / math.gcd(c, d)
k = b//f2 - a//f2

count = int(i + j - k)

print(b-a+1-count)

Submission status: Runtime Error

Solution code:
import math

def main():

    # 1 <= a <= b <= 10^18
    # 1 <= c,d <= 10^9

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


    ac = -(-a // c)
    bc = b // c

    ad = -(-a // d)
    bd = b // d

    cd = int(c * d / math.gcd(c, d))
    acd = -(-a // cd)
    bcd = b // cd

    cm_num = bc - ac + 1
    dm_num = bd - ad + 1
    cdm_num = bcd - acd + 1

    count = cm_num + dm_num - cdm_num

    total = b - a + 1

    print(total - count)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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

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

b_sum = B - ((B//C) + (B//D) - (B//lcm))

a = A-1
a_sum = a - ((a//C) + (a//D) - (a//lcm))

print(b_sum - a_sum)

Submission status: Runtime Error

Solution code:
# 190622_sat_C

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

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

# Cで割れる個数
if A % C == 0:
    n1 = math.floor((B - A) / C) + 1

elif B % C == 0:
    n1 = math.floor((B - A) / C) + 1

else:
    n1 = math.floor((B - A) / C)

# Dで割れる個数
if A % D == 0:
    n2 = math.floor((B - A) / D + 1)

elif B % D == 0:
    n2 = math.floor((B - A) / D) + 1
    
else:
    n2 = math.floor((B - A) / D)

# CとDで割れる個数
if A % lcm(C, D) == 0:
    n3 = math.floor((B - A) / lcm(C, D) + 1)

elif B % lcm(C, D) == 0:
    n3 = math.floor((B - A) / lcm(C, D)) + 1

else:
    n3 = math.floor((B - A) / lcm(C, D))


# print(n1, n2, n3)
print(B-A+1-(n1+n2-n3))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def baisu(x,a):
    if x%a ==0:
        return int(x//a)
    else:
        x -=1
        return baisu(x,a)

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))

if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
n = (C * D) // math.gcd(C,D)
C_D = (B - A + 1) / n
c = (B - A + 1) / C
d = (B - A + 1) / D
m = c + d - C_D
ans = int((B - A + 1) - m)
print(str(ans))

Submission status: Runtime Error

Solution code:

import math

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

U = B - A + 1

nA = ( math.floor(B / C) ) - (math.ceil(A / C)) +1

nB = ( math.floor(B / D) ) - (math.ceil(A / D)) +1

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

saisyoukoubaisuu = int(saisyoukoubaisuu)

nAB = (B//saisyoukoubaisuu) -(B//saisyoukoubaisuu) + 1

print( U -(nA + nB - nAB) )

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = list(map(int, input().split()))
lcm = int(C * D /math.gcd(C, D))

num_lesser_than_A_non_dividable_by_C = (A - 1) - (A - 1) // C
num_lesser_than_A_non_dividable_by_D = (A - 1) - (A - 1) // D
num_lesser_than_A_non_dividable_by_C_or_D = (A - 1) - (A - 1) // lcm
num_lesser_than_A_dividable_by_C_nor_D = num_lesser_than_A_non_dividable_by_C + num_lesser_than_A_non_dividable_by_D - num_lesser_than_A_non_dividable_by_C_or_D
num_not_larger_than_than_B_non_dividable_by_C = B - B // C
num_not_larger_than_than_B_non_dividable_by_D = B - B // D
num_not_larger_than_than_B_non_dividable_by_C_or_D = B - B // lcm
num_not_larger_than_than_B_dividable_by_C_nor_D = num_not_larger_than_than_B_non_dividable_by_C + num_not_larger_than_than_B_non_dividable_by_D - num_not_larger_than_than_B_non_dividable_by_C_or_D
print(num_not_larger_than_than_B_dividable_by_C_nor_D - num_lesser_than_A_dividable_by_C_nor_D)

Submission status: Runtime Error

Solution code:
import math

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


number =str(input())
numbers = number.split(" ")
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])
D = int(numbers[3])

number = B - A + 1

answer_C = number / C

answer_D = number / D

answer_E = number / lcm(C,D)
final_answer = number - answer_C - answer_D + answer_E
print(int(final_answer))

Submission status: Runtime Error

Solution code:
import numpy as np
import concurrent.futures as confu

def cou(i):
		if i % c != 0:
			if i % d != 0:
				return 1
		return 0
		
		
a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
count = 0
with confu.ProcessPoolExecutor() as ex:
	th = ex.map(cou, range(a,b))
	for i in th:
		count += i
print(count)

Submission status: Runtime Error

Solution code:
import math


def main():
    A, B, C, D = map(int, input().split())
    lcm = (C * D) // math.gcd(C, D)
    bc = B // C
    ac = A // C
    if A % C == 0:
        ac -= 1
    bd = B // D
    ad = A // D
    if A % D == 0:
        ad -= 1
    blcm = B // lcm
    alcm = A // lcm
    if A % lcm == 0:
        alcm -= 1
    print(B - A + 1 - ((bc - ac) + (bd - ad) - (blcm - alcm)))


main()

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d=map(int,input().split(' '))
r1=b-b%c
if a%c!=0:
	l1=a-a%c+c
else:
	l1=a
r2=b-b%d
if a%d!=0:
	l2=a-a%d+d
else:
	l2=a
lcm=(c*d)//gcd(c,d)
r3=b-b%lcm
if a%lcm!=0:
	l3=a-a%lcm+lcm
else:
	l3=a
nc=(r1-l1+c)//c
nd=(r2-l2+d)//d
nlcm=(r3-l3+lcm)//lcm
divi=nc+nd-nlcm
out=b-a+1
if c>a and c>b and d>a and d>b:
	print(0)
else:
	print(out-divi)

Submission status: Runtime Error

Solution code:
import fractions
import math
def custom_round(number, ndigits=0):
    if type(number) == int:
        return number
    d_point = len(str(number).split('.')[1])
    if ndigits >= d_point:
        return number
    c = (10 ** d_point) * 2 
    return round((number * c + 1) / c, ndigits)
a, b, c, d = map(int,input().split())
c1 = a / c
c2 = b / c
d1 = a / d
d2 = b / d
e1 = custom_round(c2-c1)
e2 = custom_round(d2-d1)
lcm = c * d // fractions.gcd(c, d)
lcm1 = a / lcm
lcm2 = b / lcm
e3 = custom_round(lcm2-lcm1)
sum = e1+e2-e3
print(int(b-a+1-sum))

Submission status: Runtime Error

Solution code:
from math import ceil,gcd

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

a,b,c,d = map(int,input().split())
e = lcm(c,d)
t1 = max(0,b//c-ceil(a/c)+1)
t2 = max(0,b//d-ceil(a/d)+1)
t3 = max(0,b//e-ceil(a/e)+1)
ans = t1+t2-t3
ans = b-a+1-ans
print(ans)

Submission status: Runtime Error

Solution code:
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

minLcm = lcm(C, D)

divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CandD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CandD

print(answer)

Submission status: Runtime Error

Solution code:
import math
def input_from_console():
    a, b, c, d = map(int, input().split())
    return a, b, c, d


def solve(a, b, c, d):
    def how_many(to, divide):
        if to >= divide:
            n = to // divide
        else:
            n = 0
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    # print('gcd', int(c*d / math.gcd(c,d)))
    count_by_cd = how_many(b, int(c*d / math.gcd(c,d))) - how_many(a - 1, int(c*d / math.gcd(c,d)))
    result = b - a + 1 - (count_by_c + count_by_d - count_by_cd)
    # print(count_by_c,  count_by_d, count_by_cd)

    # print(result)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Runtime Error

Solution code:
import sys
a,b,c,d = list(map(int, input().split()))

c_memo = 0
d_memo = 0

for i in range(c,b+1):
    if i % c == 0 and c_memo != 0 and a<=i<= b:
        c_memo = i
    if c_memo != 0:
        break
    i += c
for i in range(d,b+1):
    if i % d == 0 and d_memo != 0 and a<= i <= b:
        d_memo = i
    if d_memo != 0:
        break
    i += d

print(b-a+1 -(b-a)//d_memo -(b-a)//c_memo)

Submission status: Runtime Error

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

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

Anum = A-1 - (int((A-1)/C) + int((A-1)/D) - int((A-1)/E))
Bnum = B - (int(B/C) + int(B/D) - int(B/E))

print(Bnum - Anum)

Submission status: Runtime Error

Solution code:
from sys import stdin


class C:
	def __init__(self,A,B,C,D):
		self.A = int(A)
		self.B = int(B)
		self.C = int(C)
		self.D = int(D)
		self.list = list(range(self.A,self.B+1)) #リストの生成
		self.ans_list = list()
	def main(self):
		for i in range(self.A,self.B+1):
			if i % self.C != 0:
				if  i % self.D != 0:
					self.ans_list.append(i)

		print(len(self.ans_list))








Inp = stdin.readline()
Inp = Inp.replace('\n','')
Inp = Inp.split()

do = C(Inp[0],Inp[1],Inp[2],Inp[3])

do.main()

Submission status: Runtime Error

Solution code:
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)

N_C = (B-A) // C
N_D = (B-A) // D
N_CD = (B-A) // lcm(C,D)

if C == 1:
    ans == 0
elif D == 1:
    ans == 0
else:
    ans = (B-A)-N_C-N_D+N_CD
print(ans)

Submission status: Runtime Error

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


a,b,c,d = map(int,input().split())
c_i=a//c
d_i=a//d
cd_i=a//(lcm(c,d))
if not a%c==0:
    c_i+=1
if not a%d==0:
    d_i+=1
if not a%(lcm(c,d))==0:
    cd_i+=1

c_f=b//c
d_f=b//d
cd_f=b//(lcm(c,d))

print(b-a-(c_f+d_f-cd_f-c_i-d_i+cd_i+1)+1)

Submission status: Runtime Error

Solution code:
import numpy as np
import concurrent.futures as confu

def cou(i):
		if i % c != 0:
			if i % d != 0:
				return 1
		return 0
		
		
a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
count = 0
with confu.ThreadPoolExecutor() as ex:
	th = ex.map(cou, range(a,b))
	for i in th:
		count += i
print(count)

Submission status: Runtime Error

Solution code:
import math

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

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

b_sum = B - ((B//C) + (B//D) - (B//lcm(C,D)))

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

print(b_sum-a_sum)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
	return (x * y) // math.gcd(x, y);

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
if a % c == 0 :
	min_c = int(a/c) - 1;
else :
	min_c = int(a/c);
if a % d == 0 :
	min_d = int(a/d) - 1;
else :
	min_d = int(a/d);
if a % lcm(c, d) == 0 :
	min_cd = int(a/lcm(c, d)) - 1;
else :
	min_cd = int(a/lcm(c, d));
num_c = int(b/c) - min_c;
num_d = int(b/d) - min_d; 
num_cd = int(b/lcm(c, d)) - min_cd;
print(b - a + 1 -(num_c + num_d - num_cd))

Submission status: Runtime Error

Solution code:
import math
def baisu(x,a):
    if x%a ==0:
        return int(x//a)
    else:
        x -=1
        return baisu(x,a)

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/math.gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/math.gcd(c,d))

if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))

Submission status: Runtime Error

Solution code:
import math

ABCD = list(map(int, input().split()))

A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


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

AB = B-A
count = 0

firstC = int(A/C)
if A%C == 0:
    firstC -= 1
firstD = int(A/D)

if A%D == 0:
    firstD -= 1

firstCD = int(A/lcm(C,D))
if A%lcm(C,D) ==0:
    firstCD -= 1

endC = int(B/C)
endD = int(B/D)
endCD = int(B/lcm(C,D))

thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD
#
# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)

print(B-A+1-NoP)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
n = (C * D) // math.gcd(C,D)
C_D = (B - A + 1) / n
c = (B - A + 1) / C
d = (B - A + 1) / D
m = c + d - C_D
ans = int((B - A + 1) - m)
print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
s=0
start = a//c
end = b//c
a * b // math.gcd(a, b)
if start*c<a:
    s += end-(start+1)+1
else:
    s += end - start + 1
if d%c!=0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
last =c * d // math.gcd(c, d)
start = a//last
end = b//last
if start*c<a:
    s -= end-(start+1)+1
else:
    s -= end - start + 1
print((b-a+1)-s)

Submission status: Runtime Error

Solution code:
import math
 
a, b, c, d = list(map(int, input().split()))
 
num_mul_c = 0
num_mul_d = 0
num_mul_cd = 0
 
n=1
while True:
    nc = n*c
    if nc>b:
        break
    if (a<=nc)and(nc<=b):
        num_mul_c += 1
    n += 1
n=1
while True:
    nd = n*d
    if nd>b:
        break
    if (a<=nd)and(nd<=b):
        num_mul_d += 1
    n += 1
n=1
cd = int((c*d)//math.gcd(c, d))
while True:
    ncd = cd*n
    if ncd>b:
        break
    if (a<=ncd)and(ncd<=b):
        num_mul_cd += 1
    n += 1
print(b-a+1 - num_mul_c - num_mul_d + num_mul_cd)

Submission status: Runtime Error

Solution code:
import math

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

A -= 1

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

excluded = A - (A // C + A // D - A // lcm)
num = B - (B // C + B // D - B // lcm)

print(num - excluded)

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d=map(int,input().split( ))
r1=b-b%c
if a%c!=0:
	l1=a-a%c+c
else:
	l1=a
r2=b-b%d
if a%d!=0:
	l2=a-a%d+d
else:
	l2=a
lcm=(c*d)//gcd(c,d)
r3=b-b%lcm
if a%lcm!=0:
	l3=a-a%lcm+lcm
else:
	l3=a
nc=(r1-l1+c)//c
nd=(r2-l2+d)//d
nlcm=(r3-l3+lcm)//lcm
divi=nc+nd-nlcm
out=b-a+1
if c>a and c>b and d>a and d>b:
	print(0)
else:
	print(out-divi)

Submission status: Runtime Error

Solution code:
import math
from math import gcd as bltin_gcd
def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A, B, C, D = map(int, input().split())
N = B - A + 1  #整数列の長さ

if C == D:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    print(N-tmp)
elif coprime2(C, D):
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    mod = A % D
    tmp += math.ceil((N-mod)/D)
    mod = A % (D*C)
    tmp -= math.ceil((N-mod)/(D*C))
    print(N-tmp)
else:
    tmp = 0   #最後にNから引く
    mod = A % min(C, D)
    tmp += math.ceil((N-mod)/min(C, D))
    print(N-tmp)

Submission status: Runtime Error

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

from math import gcd


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


def mm(a, b, n):
    if a + n > b:
        return 0
    z = a + n - a % n
    return (B - z) // n + 1


E = lcm(C, D)
tc = mm(A, B, C)
td = mm(A, B, D)
te = mm(A, B, E)

print(tc, td, te)
print(B - A - (tc + td - te - 1))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>
//#include<array>

#define rep(i,n) for(int i=0;i<(n);i++)
#define LL long long int


using namespace std;

int main(void){
    LL a,b,c,d;
    cin >> a>>b>>c>>d;

    LL ans=0;
    

    LL C =b/c-a/c;
    LL D= b/d-a/d;
      /* 
    for(int i =a; i<b; i++){

        if(i%c!=0 && i%d!=0){
            ans++;
        }

    }*/
    /* vector<LL> lista(C);
    int h=0;
    for(LL i =a/c,h=0;i<b/c;h++,i++){
        lista[h]=i*a;
        cout<<lista[h]<< " " << h<< " " << i<< " " << i*a<<endl;
    }
    LL x;
  
    LL j=0;
    LL EX=0;
   for(LL i =a/d;i<b/d;i++){
        x=i*b;
         while(x>lista[j] )j++;
        cout<<x<< " " << lista[j]<< " " << h<< " " << j<<endl;
        if(lista[j]==x)EX++;
        if( h>j)break;

   }*/

    cout <<b-a+1-(C+D)<<endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import math
import fractions

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

a, b, c, d = map(int, input().split())
cd = lcm(c, d)
num = b - a + 1

if a <= cd <= b:
    cd_count = (b // cd) - (a // cd)
else:
    cd_count = 0

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)

ans = num - c_count - d_count + cd_count

print(ans)